Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize static constant member variable in nested class

Tags:

c++

Given codes in language C++

/* file xxx.hpp */

class A
{
};

class B
{
private:
    class C
    {
        static const A a;
    };
};

How can I initialize the static constant member variable A a in nested class C?

like image 256
Yang Avatar asked Nov 30 '25 05:11

Yang


1 Answers

Add the following to exactly one .cpp:

const A B::C::a;

Note that the posted code was only a declaration: this is the actual definition and initialisation.

like image 126
hmjd Avatar answered Dec 02 '25 20:12

hmjd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!