Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / C297 Error

Author
Message
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 21st May 2010 21:02
Hey, i have been writing game, when i decided to make all vars into classes, i have encountered several problems.

Including this one:

When i do instead of player.radius30;, player::radius=30;, i get error C297. And when i do player.radius=30; i get a error saying i miss a ';', before '.'. But where?



Hope you guys can help me,

Red Eye

Ultimate_H
15
Years of Service
User Offline
Joined: 11th Mar 2009
Location: A place that is neither here nor there
Posted: 21st May 2010 21:29
A couple things I noticed in your code.

When you make a class, the class is not the thing that actually holds the data, the class is a "data type" meaning you have to declare an object of the class to actually store data.

the second thing I notice is that you are trying to access private data in the classes (unless specified, members are declared private) which will give you compiler complaints.

my suggestion would be to put at the very top of both class definitions (after the opening brackets) this :

public:

That will make it so that everything is accessible from outside the class. the second suggestion I have is that you would declare an object of the class, so in this case:

player Character;

or some such, and when you reference the data in the class, you would put:

Character.something

instead of :

player.something

hope that helps
-H

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 21st May 2010 21:37 Edited at: 21st May 2010 21:44
yes, player is a type (like int float char etc..), not an object(variable), you can make a variable of the type player and use the dot (.) to access the members

so
player PLAYER;
PLAYER.speed = something;

the :: operator is used for the scope, if you want to define a function that is declared inside a class/struct, you can use it, e.g.

class player
{
public:
void Attack ( void );//prototype
}

void player::Attack ( void )
{
//define function body
}

hope it makes sense

also, you need to set the access level to public in order to access them from outside the class, for example, the default access level for classes is private, which means that they can't be accessed from outside the class, so if we have

class something
{
//private: (not necessary, it's private by default)
int x;
};

something sm;
sm.x = 0; //ERROR: you are trying to access a private member of "something" class

you could use public: access level so you can access it from anywhere

class access
{
//private members
int x;
int y;
public:
//public members
int z;
int w;
void MYFUNCTION ( void );
protected:
float h;
};

void access::MYFUNCTION ( void )
{
x = y = z = w = h = 0; //this function is inside the class, and thus can access private (and protected) members
}

access myClass;
myClass.x = 0; //ERROR: private members
myClass.z = 1; //fine: public member
myClass.h = 1; //ERROR: protected member
myClass.MYFUNCTION ( ); //fine: public member

note the protected access level, it is mainly used for inheritance and friendship, you should read some more about classes

Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 21st May 2010 23:19
Ty very ,much for the info mates, it works perfectly!

Thanks for the help. U mates saved me.

Login to post a reply

Server time is: 2024-07-07 00:10:35
Your offset time is: 2024-07-07 00:10:35