Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Where do I define a struct in order to be accessible to all my classes?
SlowerPhoton last edited by SlowerPhoton
The files I have are the following:
In which one should I put the struct definition?
Hi, welcome to the forum.
There are two things here - the declaration and an instance of that struct.
The declaration should go in neither of these files. It should go into
myawesomestruct.h, and get included in
.cppfiles you need it in.
As for an instance of that struct - that depends on what that struct is and how it should be interacted with.
It can be a global instance - declared as
externin a header and defined in its own
It can be a member of a globally accessible instance of some class.
It can be a dynamically added property on a globally accesible object (e.g. the application object).
It can be a member passed as a parameter between other classes methods.
It can be a member of a class which instance is passed around.
... <- enter 10 other options here
It all depends on the purpose of that struct and intended usage pattern.