c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -


my situation follows. let there header file classdeclarations.h, have following classes declared:

class classa; class classb;  class classa     {     public:         classa(int x);         classa(double y);          int returninteger(void) { return m_x; }         double returndouble(void) { return m_y; }     private:         int m_x;         double m_y;     }  class classb     {     public:         classb(int x);          int returninteger(void) { return m_x; }     private:         int m_x;         classa m_instancea_1;     } 

let there *.cpp file called classdefns.cpp, define methods of classes declared in classdeclarations.h:

#include classdeclarations.h  classa::classa(int x) : m_x(x)     {     }  classa::classa(double y) : m_y(y)     {     }  classb::classb(int x) : m_x(x)     {  //  line build error occurs     m_instancea_1 = classa(0);     } 

note have commented line compiler says there error:

error c2512: 'classa' : no appropriate default constructor available

the above example not minimal not working example (it works), captures gist of more complicated situation getting error.

this stackoverflow question regarding same error resolved answer clarified default arguments should specified. not have default arguments in situation anymore (but did, in past). double checked make sure there no default constructor arguments.

this question regarding same error resolved ensuring name of constructors same name of class. have double checked make sure not issue situation.

this question regarding same error different case, because here asker did not want have default constructor defined.

this question regarding same error resolved ensuring default constructor method declared in body of class declaration. so, not applicable case since have constructors declared in class declaration well.

this question regarding same error resolved ensuring declaring header file included. not problem in situation.

this question regarding same error perhaps relevant, don't understand enough, , appreciate clarification on might assuming existence of default constructor?

classb::classb(int x) : m_x(x), m_instancea_1(0)                                 //^^^^^^^^^^^^, constructs classa instance { } 

edit

getting c2512 “no default constructor”

if still need ability default construct classa instance need add default constructor. default constructor no longer auto generated once other constructors provided.

class classa { public:     classa(); // provides default constructor declaration (you still need implement it)     classa(int x);     classa(double y);  ... }; 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -