c++ - Init. static members while COPY CTOR is private -


i have class x, , goal have special var indicates "bad object", in order implement function returns x&.
example:

//x.h class x{ private:   int i;   x(const x& other){} //private copy ctor  public:   const static x& badobject;    x(int a) : i(a) {} // ctor    const x& f(){    if(true)     //return valid x object    else       return badobject; }; 

the ctor not default ctor, , copy ctor private (i don't want allow coping of object.) operator= private.
now, when try init. badobject in x.cpp error:

//x.cpp #include "x.h" const x& x::badobject = x(1); 

because copy ctor private.

what doing wrong here? should resolve this?
thanks!

change declaration to

const static x badobject;

and definition to

const x x::badobject(1);

this create 1 instance of badobject. function returns value ref, there no need copy constructor or more.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -