Go Down

Topic: class setters setting member variable (Read 459 times) previous topic - next topic

a.mlw.walker

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: [Select]

void setName(String name)
{
_name = name;
}

doing it from the constructor works:
Code: [Select]

MyClass::MyClass(int value, String name, String description)
{
  _value = value;
  _name = name;
  _description = description;
}

whats wrong?

PaulS

Code: [Select]
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.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy