in the main file and class 'b' need to be defined before class 'a' because class 'a' is using class 'b'.
and know for doing what you said I need to get access from class 'b' to class 'a', and right now class 'b' doesnt know about class 'a'.
what do you suggest - moving both classes to separate files?
usually you have to forward define one of the two. es: class a; class b{ public: void method(a&); }; class a{ public: int f{}; b sub_obj{}; void method(); }; void b::method(a& parent){ parent.f=54; } void a::method(){ sub_obj.method(*this); }
Обсуждают сегодня