Let's say we have the following class:
class A {
static SomeLongType b;
};
Now we have to initialize it in the appropriate cpp file. I can think of the following ways:
SomeLongType A::b{}; // repetition of SomeLongType
decltype(A::b) A::b{}; // A::b written two times
Both seem to be kind of cumbersome to me. Is there a better way?
The perfect solution would be to use C++11 auto
. But as ecatmur commented, thats not allowed by the language.
Why not just define a simple macro?
#define DEFINE(x) decltype(x) x{}
struct A
{
static SomeLongType b;
};
DEFINE( A::b );
I really hate C macros, but they are usefull in certain cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With