struct OBJECT
{
int coord_x;
move_right(int move_distance)
{
coord_x += move_distance;
}
};
main()
{
OBJECT example;
example.coord_x = 200;
example.move_right(25);
}
Would something like that work?
C++ Struct containing function question.
I was wondering if a function contained in a struct could modify variables of the struct.
Example
Yes, a struct is exactly the same as a class in C++ (except that it's members are "public:" by default).
Quote:Original post by Hodgman
Yes, a struct is exactly the same as a class in C++ (except that it's members are "public:" by default).
and it defaults to public inheritance instead of private :)
Though I am curious about the reasoning behind not trying it out yourself in the first place ;)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement