parent class, child class, constructor

Started by
1 comment, last by Pero83 12 years, 4 months ago
Hey all. Got a little problems with understand one thing around constructors.




In Frank Luna's Book, author has this class D3Dapp:

D3Dapp::D3Dapp(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD verProc)




Then he has child class:

HelloDirect3D::HelloDirect3D(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD VerProc):D3Dapp(hInstance, winCaption, devType, VerProc)




And finally, he creates object of child class:

HelloDirect3D mApp(hInstance, "X", D3DDEVTYPE_HAL, D3DCREATE_HARDWARE_VERTEXPROCESSING);







Now, i'm having a little problems understand what exactly is going on around here.

If i start with object; i create object from HelloDirect3D child class, and give those 4 parameters. But i did not state parameters for parent class ? So when i use hInstance or "X" in object as argument......does it assign them to child class, or parent class, or what? I thought parent's constructor always gets "calculated" first, only then childs.

So i'm having problems understand, to wich constructor does those parameters goes?

Or, was it, when i created subclass of D3Dapp, and and first declared arguments for childs constructor...those same arguments translated to the parent class with

HelloDirect3D::HelloDirect3D(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType2, DWORD VerProc):D3Dapp(hInstance, winCaption, devType2, VerProc)




Tnx!
Advertisement
The part after a colon in a constructor is the member initialization list. It specifies how base classes and member variables are initialized. If you have the name of a base class after the colon, the parts in the parentheses after the name are the arguments passed to the constructor of the base class. Similarly the parts in the parentheses after a member variable name are the arguments passed to the constructor for the member variable.
Ok tnx a lot, i think i understand it now!

This topic is closed to new replies.

Advertisement