Passing parameter to a get method, could it cause some error in C ++?

1

I'm starting to study OOP now and it's kind of weird to me. But I would like to know if I pass some parameter in a get method, can it result in some error? Ex:

class MostraNum
{
      private:
      int x;
      public:
      int getRetornaNum(int x)
      {
          return x;
      }
};

int main()
{
     MostraNum result;
     cout<<result.getRetornaNum(100)<<endl;
     return 0;
}
    
asked by anonymous 11.04.2018 / 19:47

1 answer

1

No,

Get is just a name used by convention and does not mean anything.

Your function will return the passed parameter and not the member variable 'x' because c ++ prioritizes local variables when the name is the same, if you want to return the member variable x should do explicitly:

return MostraNum::x

But for organization reasons and to make it easier to read your code, give your member variable a special name and do not use repeated names, such as #

    
19.04.2018 / 15:21