Jump to content
  • Advertisement
Sign in to follow this  
highowl

C++ Struct containing function question.

This topic is 3142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering if a function contained in a struct could modify variables of the struct. Example
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?

Share this post


Link to post
Share on other sites
Advertisement
Yes, a struct is exactly the same as a class in C++ (except that it's members are "public:" by default).

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!