Troubles with reference variables/pointers an class members [C++] -


i've been working on project , have quite few classes, few of this:

class {     // stuff; };  class b {     a& test;  public:     b(a& _test) :         test(_test)     {};     void dostuff(); };  class c {     foo;     b bar(foo);      void exp()     {         bar.dostuff();     } }; 

this ends breaking in class c when c::foo not type name. in bigger project, broken separate .cpp , .h files, don't see error if #include"c.h" in b.h, there still error in c.cpp bar unrecognized compiler (visual studio 2013). there error persists if a& a* instead (changing code references pointers necessary, of course). have tips going on here?

this line of code:

b bar(foo); 

attempts declare member function named bar returns b , takes argument of type foo. however, in code, foo not type - it's variable. i'm guessing meant initialize bar instead:

b bar{foo}; // non-static data member initializers must done {}s 

or write out constructor:

c() : bar(foo) { } 

additionally, constructor assigns reference test temporary _test:

b(a _test) :     test(_test) { } 

you want take _test reference:

b(a& _test) : test(_test) { } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -