Reputation: 515
How can I initialize a static const class member of a custom class in C++?
Here is what I tried so far:
Header file:
class A
{
private:
static const B b;
};
Source file:
const B A::b;
Class`s B constructor has no parameters.
The approach does not work. The b
becomes red underlined in the source file and it is written over there const member "A::b" requires an initializer
.
Upvotes: 1
Views: 136
Reputation: 597
Did you provide a default constructor for B?
class B
{
public:
B() {}
};
It worked here
Upvotes: 2