Initializer List {Solved}

I am aware that the use of a colon runs the base class constructor but this does not have a base class it looks like...This is a code snippet from Frank D Luna, 3D Game Programming in DirectX11
....and no I am not talking about the scope resolution operator lel
1
2
3
4
5
//Header File 
class D3DApp
{
public:
    D3DApp(HINSTANCE hInstance);


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//CPP file
D3DApp::D3DApp(HINSTANCE hInstance) //////////What does this colon mean???
:	mhAppInst(hInstance),       //// <----It is on this line
	mMainWndCaption(L"D3D11 Application"),
	md3dDriverType(D3D_DRIVER_TYPE_HARDWARE),
	mClientWidth(800),
	mClientHeight(600),
	mEnable4xMsaa(false),
	mhMainWnd(0),
	mAppPaused(false),
	mMinimized(false),
	mMaximized(false),
	mResizing(false),
	m4xMsaaQuality(0),
 
	md3dDevice(0),
	md3dImmediateContext(0),
	mSwapChain(0),
	mDepthStencilBuffer(0),
	mRenderTargetView(0),
	mDepthStencilView(0)
{
	ZeroMemory(&mScreenViewport, sizeof(D3D11_VIEWPORT));

	// Get a pointer to the application object so we can forward 
	// Windows messages to the object's window procedure through
	// the global window procedure.
	gd3dApp = this;
}
Last edited on
The ':' operator* is different from the '::' operator just like the '=' operator is different from the '==' operator. In this case the double colon tells the compiler which class you are defining this particular function for.

EDIT:* - Scratch that since the single colon isn't really an operator in any sense of the term used in C or C++. Just try to remember that if something looks different, it's because it is different.
Last edited on
Im not talking about the scope resolution operator!!! AHHHHHH I knew someone was gonna say that

Look at my comment in the code

I am pretty sure its just multiple inheritance but the class doesn't inherit from another class...or explicitly say so

Line 3 of the cpp file
Last edited on
Oh crap! My bad. That's called an initializer list: http://en.cppreference.com/w/cpp/language/initializer_list
This is a faster way to assign values to an object during construction.

EDIT: Yes I screwed that up again.... I do that a lot :/
Last edited on
Nice! Thanks!
On another note:
Can you tell me the purpose of calling the base class constructor on an inherited class constructor, or tell me what the method or technique is called so I can look that up
Last edited on
You would call the base class constructor whenever the base class requires anything but it's default initialization. Also, sometimes data members of the base class cannot be accessed by the inherited class due to the access level so that's another reason.

I should note that no matter what you do, some form of constructor or another for the base class is going to be called by the inherited class.
Topic archived. No new replies allowed.