The Mesh class contains all the necessary functions for working with models. The Box and Sphere classes are inherited from it, while having their own constructors.

class Mesh { public: void move(float x,float y,float z) { ... } void turn(float x,float y,float z) { ... } void flip() { ... } void setTexture(char filename[]) { ... } void setSize(float x,float y,float z) { ... } }; class Box : public Mesh { public: Box(float x,float y,float z) { ... } }; class Sphere : public Mesh { public: Sphere(float x,float y,float z, int segments) { ... } }; 

The fact is that now I need to write a constructor for Mesh, which will load 3D models, but when I write something like that in Mesh

 Mesh(float x,float y,float z,char filename[]) { ... } 

The compiler throws the error "no default constructor exists for class". If you add an empty Mesh () constructor; then an error occurs

 error LNK2001: unresolved external symbol "public: __thiscall Mesh::Mesh(void)" (??0Mesh@@QAE@XZ) 


    2 answers 2

    Mesh expression (); is a no-argument constructor declaration . The constructors of the inherited classes Box and Sphere implicitly call the constructor of the base class Mesh () , so it must have an implementation , for example, empty:

     Mesh() {} 

    or default implementation (available in C ++ 11):

     Mesh() = default; 

    Before you added a new constructor with four parameters, the compiler created an empty constructor for you, again, implicitly.

    • Thanks, it worked. - hashcode_
    • @hashcode_: Then mark the answer as true (there is a daw next to the answer). - VladD

    I have compiled this code normally. You have a link error. Try deleting all build files and recompiling.