constructor function inheriting variables?

Hello everyone, I am learning to work with irrLicht and I have come across a piece of code I do not understand. I was hoping someone could help me with this.
Long bit of code ahead, but you do not have to read through it all. The following is a class (CDemo) of which I made an object (CDemo demo(false, true, true, true, true, true, video::EDT_DIRECT3D9);).
So when I created the object the constructor function got called. And that brings us to the bit of code further down. My question is. What does the : fullscreen(f), music(m), ..... do? It looks like inheritance, but since CDemo::CDemo is a constructor function rather than a new class it doesn't make any sense to me. The variables also don't have 'public', 'private' or protected in front of them and they have (parameter) behind them as if they were functions. So what is that piece of code and what does it do? does 'fullscreen(f)' make demo.fullscreen the value f (false)?
Any help is appreciated :)

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class CDemo : public IEventReceiver
{
public:

	CDemo(bool fullscreen, bool music, bool shadows, bool additive, bool vsync, bool aa, video::E_DRIVER_TYPE driver);

	~CDemo();

	void run();

	virtual bool OnEvent(const SEvent& event);

private:

	void createLoadingScreen();
	void loadSceneData();
	void switchToNextScene();
	void shoot();
	void createParticleImpacts();

	bool fullscreen;
	bool music;
	bool shadows;
	bool additive;
	bool vsync;
	bool aa;
	video::E_DRIVER_TYPE driverType;
	IrrlichtDevice *device;

#ifdef USE_IRRKLANG
	void startIrrKlang();
	irrklang::ISoundEngine* irrKlang;
	irrklang::ISoundSource* ballSound;
	irrklang::ISoundSource* impactSound;
#endif

#ifdef USE_SDL_MIXER
	void startSound();
	void playSound(Mix_Chunk *);
	void pollSound();
	Mix_Music *stream;
	Mix_Chunk *ballSound;
	Mix_Chunk *impactSound;
#endif

	struct SParticleImpact
	{
		u32 when;
		core::vector3df pos;
		core::vector3df outVector;
	};

	int currentScene;
	video::SColor backColor;

	gui::IGUIStaticText* statusText;
	gui::IGUIInOutFader* inOutFader;

	scene::IQ3LevelMesh* quakeLevelMesh;
	scene::ISceneNode* quakeLevelNode;
	scene::ISceneNode* skyboxNode;
	scene::IAnimatedMeshSceneNode* model1;
	scene::IAnimatedMeshSceneNode* model2;
	scene::IParticleSystemSceneNode* campFire;

	scene::IMetaTriangleSelector* metaSelector;
	scene::ITriangleSelector* mapSelector;

	s32 sceneStartTime;
	s32 timeForThisScene;

	core::array<SParticleImpact> Impacts;
};



1
2
3
4
5
6
7
8
9
10
11
12
CDemo::CDemo(bool f, bool m, bool s, bool a, bool v, bool fsaa, video::E_DRIVER_TYPE d)
: fullscreen(f), music(m), shadows(s), additive(a), vsync(v), aa(fsaa),
 driverType(d), device(0),
#ifdef USE_IRRKLANG
	irrKlang(0), ballSound(0), impactSound(0),
#endif
 currentScene(-2), backColor(0), statusText(0), inOutFader(0),
 quakeLevelMesh(0), quakeLevelNode(0), skyboxNode(0), model1(0), model2(0),
 campFire(0), metaSelector(0), mapSelector(0), sceneStartTime(0),
 timeForThisScene(0)
{
}
It's an initialization list, something unique to constructors in C++-

See here:
http://www.cprogramming.com/tutorial/initialization-lists-c++.html

and here:

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.6
Thanks! got it now. Not sure why they chose to do it like this. Because there is no difference between the following two bits of code, right? (at least in the output)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

class Test
{
    public:
		Test() : number(1) { }
		void tstFunc(){
			std::cout<<number;
		}

	private:
		int number;
};


int main()
{
    Test tstObj;
	tstObj.tstFunc();
    return 0;
}

and
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

class Test
{
    public:
		Test()  { number = 1;}
		void tstFunc(){
			std::cout<<number;
		}

	private:
		int number;
};


int main()
{
    Test tstObj;
	tstObj.tstFunc();
    return 0;
}
Last edited on
You didn't read through the articles, right? There is a HUGE difference between initialization lists and doing stuff in the constructor body. As a rule of thumb, ALL initializations should be done in the initialization list. The difference may seem subtle at first, but it can get you into very muddy areas full of subtle errors if you do your initialization in the body. Read through the links I gave you again.
Topic archived. No new replies allowed.