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
This Code
why does this gives complier error?
Here''s why; when you say
inside the class declaration, you should place the semi-colon outside of the brackets, as follows:
This is true for all of the functions declarations in your class section.
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.
You do need the semicolon at the end of the line if your just declaring the function, but not if you included the implementation.
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:
This should work. You will need to do similar things for each of the other member functions.
Hope that helps you out!
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
Popular Topics
Advertisement
Recommended Tutorials
Advertisement