mardi 2 octobre 2018

Extremly weird C++ code: Member function gets called, constructor doesn't get called [on hold]

I'm currently trying to understand a large C++ program and stumbled across a function with the following signature:

template<class *templateType*>inline bool& *namespace*::*Classname*<*templateType*>::*functionName*()

I put a "system("touch /opt/membertest");" in this function and a "system("touch /opt/constrtest");" in every constructor of this class that exists. Running this program creates the file "/opt/membertest" but not the file "/opt/constrtest". How is this possible? After all I know, you cannnot call a non-static member function without creating an instance of this class, and you cannot create an instance without calling the constructor.

I would be thankful if anyone could help me and explain to me how this weird behaviour might work.

Note: The Program gets compiled using the C++11 Standard.

Note: The line of the class definition is:

template<class *templateType*>
class *className*
:
    public *bassClassName*
{

Note: Some of the constructors have member initialization lists.

PS:

In case anyone cares: The program I'm talking about is OpenFOAM and the class I'm talking about is KinematicParcel

Aucun commentaire:

Enregistrer un commentaire