C++ object referencing in classes
I am wondering how to store a reference of an object inside of another object, and also set that reference as a private property. Example (pseudo-code): class foo { public: int size; foo( int ); }; foo::foo( int s ) : size( s ) {} class bar { public: bar( foo& ); private: foo fooreference; }; bar::bar( foo & reference ) { fooreference = reference; } foo firstclass( 1 ); bar secondclass( firstclass ); As you may be able to see, I just want to be able to store the reference of foo inside this bar class. I know how to simply bring it into a method and use it just in the scope of that method, but