Class issues

Hey folks,

I've been trying to get a class to work, and even though I've worked with classes before, this time I have no clue as to what is going wrong.

This is my class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class CCommander
{
public:
	CCommander();
	void move();
	void arc();
	void flyDown( int y_pos );
	void exitScreen();
	int x;
	int y;
	Surface* Graphic;
private:
	int x_start;
	int arcStage;
	int arcDegrees;
};


And this is it's constructor:

1
2
3
4
5
6
7
CCommander::CCommander()
{
	CCommander.arcDegrees = 0;
	CCommander.arcStage = 0;
	CCommander.Graphic = new Surface("assets\\CCommander.tga");
	CCommander.x = 50;
}


Now, the errors that I get when compiling is that I'm missing a semicolon (;) before a dot (.):

1
2
3
4
5
6
7
8
1>c:\school\year 1\pr1\galaxians\game.cpp(14) : error C2143: syntax error : missing ';' before '.'
1>c:\school\year 1\pr1\galaxians\game.cpp(14) : error C2143: syntax error : missing ';' before '.'
1>c:\school\year 1\pr1\galaxians\game.cpp(15) : error C2143: syntax error : missing ';' before '.'
1>c:\school\year 1\pr1\galaxians\game.cpp(15) : error C2143: syntax error : missing ';' before '.'
1>c:\school\year 1\pr1\galaxians\game.cpp(16) : error C2143: syntax error : missing ';' before '.'
1>c:\school\year 1\pr1\galaxians\game.cpp(16) : error C2143: syntax error : missing ';' before '.'
1>c:\school\year 1\pr1\galaxians\game.cpp(17) : error C2143: syntax error : missing ';' before '.'
1>c:\school\year 1\pr1\galaxians\game.cpp(17) : error C2143: syntax error : missing ';' before '.'


Also, for some reason I'm getting this error twice for every line of the constructor.

I don't a clue as to why I'm getting these errors since as far as I know I'm using the class members correctly.

I hope someone knows anything about this since it's been bugging me for 2 days now >.>

//Rycul
1
2
3
4
5
6
7
CCommander::CCommander()
{
	CCommander.arcDegrees = 0;
	CCommander.arcStage = 0;
	CCommander.Graphic = new Surface("assets\\CCommander.tga");
	CCommander.x = 50;
}


You don't put the classname before the '.' operator... you put the object name.

However when you're inside the class, you don't need any qualifier before variable names because it assumes you're using 'this' as the object. Therefore you can just do this:

1
2
3
4
5
6
7
CCommander::CCommander()
{
	arcDegrees = 0;
	arcStage = 0;
	Graphic = new Surface("assets/CCommander.tga");  // also, use '/' to separate directories.
	x = 50;
}
Last edited on
Your help is very much appreciated, it's working now. TBH I already had several tries where I tried to declare an objectname for this class but it wouldn't work so I kept removing that.

Anyway, must've had been other problems that were causing that all.

Thanks a lot, you've saved my day ;)
Topic archived. No new replies allowed.