Started learning WxWidgets. You need to create an XYZArray via WX_DECLARE_OBJARRAY and WX_DEFINE_OBJARRAY. But something does not work, although I did everything as in the documentation.

#ifndef WXPOINTS_H_INCLUDED #define WXPOINTS_H_INCLUDED //#include "xyz.h" #include <wx/dynarray.h> class XYZ; WX_DECLARE_OBJARRAY(XYZ, XYZArray); class XYZ { public: float x; float y; float z; //void print(); }; #include <wx/arrimpl.cpp> WX_DEFINE_OBJARRAY(XYZArray); class wxPoints { public: wxPoints(); XYZArray arr; void Test(); }; #endif // WXPOINTS_H_INCLUDED 

Throws out errors: Actually, the mistakes

    1 answer 1

    The source code in which the XYZArray is defined is connected twice. You should not include CPP files via include, and in H-files there should be a check for repeated inclusion.

    • one
      And how should it be? Can you please write? - user220796
    • You just need to collect all the ads in H-files, and the implementation - in the same CPP-files. For example, the XYZArray class is described. Then XYZArray.h will contain #ifndef XYZArray_h #define XYZArray_h , then the class declaration and #endif . This will "protect" the file from being re-enabled. The class method definitions are located in XYZArray.cpp , and this file is not included anywhere: wherever the XYZArray class is required, #include "XYZArray.h" is appended to the file header. That's all, no magic. - Ildar Khairullin
    • Why scare newbies with complex designs? It is enough to write #pragma once at the beginning of each header, it adheres to a huge number of compilers. - int3
    • There it is no longer a matter of specific lines, but in principle of placing ads and definitions. I just brought a canonical solution. #pragma once is a non-standard, therefore, apparently, I occasionally met him in the listings, but not in educational literature. I live yesterday afternoon. :) - Ildar Khayrullin