Advertisement

This Code

Started by August 17, 2000 08:33 PM
3 comments, last by vbisme 24 years, 4 months ago
why does this gives complier error?
        
struct BlockInfo
{
	int Color;
	int State;
	int Bonus;
	int Points;
};

class Block : public Sprite
{
public:
	void SetState(int newState) { myInfo.State = newState; }
	void SetBonus(int newBonus) { myInfo.Bonus = newBonus; }
	void SetPoints(int newPoints) { myInfo.Points = newPoints; }
	void SetInfo(BlockInfo newInfo);


private:
	BlockInfo myInfo;
};

void SetInfo(BlockInfo newInfo)
{
	SetState(newInfo.State);
	SetBonus(newInfo.Bonus);
	SetPoints(newInfo.Points);
}

        
it gives me... : error C2065: 'SetState' : undeclared identifier : error C2065: 'Setbonus' : undeclared identifier : error C2065: 'SetPoints' : undeclared identifier I tried using the this like... this->SetState(newInfo.State); but it gives me something like... error C2673: 'SetInfo' : global functions do not have 'this' pointers Edited by - vbisme on 8/17/00 8:37:11 PM
:0 oopps should be...
void Block::SetInfo()

hehehe
Advertisement
Here''s why; when you say

	void SetState(int newState) { myInfo.State = newState; } 


inside the class declaration, you should place the semi-colon outside of the brackets, as follows:

	void SetState(int newState) { myInfo.State = newState ); 


This is true for all of the functions declarations in your class section.

adpeace:

The semicolon goes after each statement, it doesn''t matter if the function is inline or not.

class Somthing{	void foo() {DoSomthing();} //correct	void bar() {DoSomthingElse()}; //compiler error	}; 


You do need the semicolon at the end of the line if your just declaring the function, but not if you included the implementation.
In your definition of SetInfo(), you need to tell the compiler that you are defining a member of the Block class and not a global function:

    void Block::SetInfo(BlockInfo newInfo){  SetState(newInfo.State);  SetBonus(newInfo.Bonus);  SetPoints(newInfo.Points);}    


This should work. You will need to do similar things for each of the other member functions.

Hope that helps you out!

This topic is closed to new replies.

Advertisement