I'm trying to learn how to use a class to hold multiple values and return an instance from a function. The other option is to use global variables, which is probably simpler, but I'd like to learn classes in C++.
The only thing that's giving me trouble is assigning to the string field from the constructor parameter. I've tried several variations of this code, and none of it compiles.
This is the error I currently get:
In constructor 'RelayInfo::RelayInfo(int, char*)': 17: error: incompatible types in assignment of 'char*' to 'char [20]'
It's been a long time since I've dealt with pointers and such in C.
//The RelayInfo class only has public fields and a constructor.
//Its only purpose is to hold these values.
class RelayInfo
{
public:
RelayInfo(int pin, char message[20]);
int Pin;
char Message[20];
};
RelayInfo::RelayInfo( int pin, char message[20] )
{
Pin = pin;
Message = message*;
}
void setup() {
pinMode(13, OUTPUT);
digitalWrite( 13, LOW );
}
void loop() {
//Construct an instance of the class:
RelayInfo info( 13, "Hello, World!" );
//Use the fields from the class.
if( info.Message == "Hello, World!" )
{
digitalWrite( info.Pin, HIGH );
}
}