Jump to content
  • Advertisement
Sign in to follow this  
Pero83

parent class, child class, constructor

This topic is 2551 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!