dimanche 28 janvier 2018

Child calls the default contractor of its parent after calling parent's construct with argument

I have following inheritance schema;

class Shader{ [...] }

class Program{ [...] }

class Object : public Shader, public Program{ 
Object::Object(const char * ObjFilePath, const std::string sourcePathVertexShader, const std::string sourcePathFramentShader) : Shader(sourcePathVertexShader, sourcePathFramentShader), Program(this->m_gShader[0], this->m_gShader[1])
{[...]}

}

i.e we are deriving Object class from Shader and Program class, and while initialising the Object class, we are calling the parents' contractors with argument.

Note m_gShader vector is a member in Shader class.

I have traced the code with Xcode, and the code does the thing that it is supposed to do, after calling the parents' constructors with argument, it also calls the same parents' default constructors, which causes all of the member variables of the parents' to reset their value.

Why is this happening ? and how can we prevent this from happening ?

Aucun commentaire:

Enregistrer un commentaire