Jump to content
  • Advertisement
Sign in to follow this  
p80

functions and arrays within a class - scope question

This topic is 4913 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

Hello, in C++, data members of a class have global scope within that class. by that reasoning, it shouldn't be absolutely nessacary to pass data members to functions within the same class. Is this correct? I'm useing visual c++ 6, just in case this varies from compiler to compiler. thanks for your time.

Share this post


Link to post
Share on other sites
Advertisement
you never have to pass member variables to member functions within the same class instance:


class Example
{
public:
int getFirstPlusSecond();

private:
int first;
int second;
};

int Example::getFirstPlusSecond()
{
return first + second;
}





-me

Share this post


Link to post
Share on other sites
If you mean - can you do this:


class MyClass
{
int x_;
public:
MyClass(int x) : x_(x) {}
void SetX(int x) {x_ = x;}
int GetX() const {return x_;}
};



Then yes, no worries.

Jim.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!