Pages: [1]   Go Down
Author Topic: class setters setting member variable  (Read 335 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 142
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Im new to making classes, so far everything has gone well, however I want to make a list of objects, and set the private variables of the objects with methods - setters... however arduino tells me that the member variable is not declared within this scope. I am able to set the variables from the constructor, so I just tried to do it the same way from a method
Code:
void setName(String name)
{
_name = name;
}
doing it from the constructor works:
Code:
MyClass::MyClass(int value, String name, String description)
{
  _value = value;
  _name = name;
  _description = description;
}
whats wrong?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void setName(String name)
{
_name = name;
}
Perhaps that fact that you left the MyClass:: part of the front of the function name is a problem.
Logged

Pages: [1]   Go Up
Jump to: