I writing OOP software with C++ that i need pass instances of my classes between files, 50…60 files. Unfortunately , I used a library that uses a callback function and not an object.
Question:
I used a few sates such as struct between cpp files, but i got multiple definition error or … How do I pass ONE instance from each class between 50…60 classes?
Class A{}; A *instanceA = new A();
Class B{}; B *instanceB = new B();
.
.
.
Class Z{}; Z *instanceZ = new Z();
I need to pass intaanceA, intanceB and so on between files. Do you have any idea?
I suspect you defined the instance in a header file and included that in multiple files:
A.h:b.cppandc.cppboth#include <A.h>, causing multiple definition error.To correct you can use
externto declare the instance in the header file and define it in exactly one.cppfile:A.h:A.cpp:Another cause is using
externin the header file but defininginstanceAin multiple.cppfiles (as was the case here).