Skip to main content
gamedev.net
🔒 Locked

structure and classes

Started by da_cobra 0 replies 250+ views
Original Post
da_cobra
da_cobra
If I want to use a struct like this on in a class :
struct HighScoreLine
{
char name[10] ;
long score ;
}
[\code]

where do I put this line? In my class as private? In my header file of my class above the declaration of my class? Or in my .cpp file before my class?

thanx in advance   
Forgemaster
Forgemaster
quote:
In my class as private? In my header file of my class above the declaration of my class? Or in my .cpp file before my class?


You can:
- Put it in your class as private. That will have the advantage of only allowing that class to use the struct.
- Put it in your class as protected. That will allow that class and all the class derived from it to use/access it.
- Put it in youe class as public. That will allow any program who owns an instance of your class to access it, through the class.
- Put it in the header file, above the declaration of the class. This will allow your class AND all other files who include your header file to use the struct.

You can also have all the combinations of having the struct n the header and defining it in your class as private/protected/public. It all depends on the amount of control you want over that struct.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.