The question title might not be perfectly clear.
From c++11 on it is possible to declare and initialize class members like int something = 42;
in the code below.
On the other hand it's not possible to call a constructor like Foo foo(2)
in the example below.
class Foo
{
int something = 42;
int value;
public:
Foo(int ivalue) { value = ivalue; } // do stuff with value
};
class Bar
{
Foo foo(2); // <<< does not compile
int thisisok = 2; // this is OK
public:
// ...
};
class BarOK
{
Foo foo;
public:
BarOK() : foo(2) // OK
{ }
};
Is there any reason why this is would not be possible (maybe in future c++ standards)?
Or is the case I present here too simplistic.