Hi guys,
so I'm new in OO C++ programming. Lets say I have two objects - object A and object B defined at global scope in main.cpp file. If I want to Access function from object A in object B, what should I do?
Should I in main.cpp when defining objects use "extern" like in example below? Or should I do something else?
It would be clearer if you post complete compile-able code.
Some of your terminology is off a bit: A class is not an object, rather an object is an instance of a class.
There shouldn't normally be a need for extern, just include the header file of the class for which you want to use. But watch out for circular includes: A includes B and B includes A. In that case use a forward declaration of a class :
The error you post and the code snippet you give us don't really go with the initial code you posted. Also, you don't show us what members classes A and B have.
Please give us as much information as possible. We don't want to offer possible solutions based on guesses as to what the code really contains.