structs in libraries
hi all;
i trying create library struct. starting out simply, header file has;
class sourcemodes
{
public:
typedef struct
{
int maxval;
uint8_t scale;
uint8_t srcsnk;
uint8_t cvcc;
} srcmodes_t;
};
then constructor in cpp file has;
sourcemodes::sourcemodes (void) {
sourcemodes::srcmodes_t srcmodes;
srcmodes.maxval = 1023;
srcmodes.scale = 1;
srcmodes.srcsnk = 0;
srcmodes.cvcc = 0;
}
the arduino compiler gives me error on line
sourcemodes::sourcemodes (void) {
sourcemeter.cpp:14: error: definition of implicitly-declared 'sourcemodes::sourcemodes()'
i'm not sure how create class struct, , no methods.
does have idea i'm doing wrong? array of structs includes ints, , strings. maybe that's old school c , if there's better cpp way, i'd try it.
thanks help
i trying create library struct. starting out simply, header file has;
class sourcemodes
{
public:
typedef struct
{
int maxval;
uint8_t scale;
uint8_t srcsnk;
uint8_t cvcc;
} srcmodes_t;
};
then constructor in cpp file has;
sourcemodes::sourcemodes (void) {
sourcemodes::srcmodes_t srcmodes;
srcmodes.maxval = 1023;
srcmodes.scale = 1;
srcmodes.srcsnk = 0;
srcmodes.cvcc = 0;
}
the arduino compiler gives me error on line
sourcemodes::sourcemodes (void) {
sourcemeter.cpp:14: error: definition of implicitly-declared 'sourcemodes::sourcemodes()'
i'm not sure how create class struct, , no methods.
does have idea i'm doing wrong? array of structs includes ints, , strings. maybe that's old school c , if there's better cpp way, i'd try it.
thanks help
you able this:
but not want. struct srcmodes temporary variable defined inside constructor , out of scope constructor returns. want move srcmodes_t srcmodes; class definition srcmodes becomes member variable of class. struct treated class in c++ if struct definition, can new , structs if class definition. default, member in class private unless list under public. default, member in struct public unless list under private.![smiley :)](https://forum.arduino.cc/smileys/arduino/smiley.gif)
code: [select]
class sourcemodes
{
public:
typedef struct
{
int maxval;
uint8_t scale;
uint8_t srcsnk;
uint8_t cvcc;
} srcmodes_t;
};
then constructor in cpp file has;
sourcemodes::sourcemodes (void) {
srcmodes_t srcmodes;
srcmodes.maxval = 1023;
srcmodes.scale = 1;
srcmodes.srcsnk = 0;
srcmodes.cvcc = 0;
}
but not want. struct srcmodes temporary variable defined inside constructor , out of scope constructor returns. want move srcmodes_t srcmodes; class definition srcmodes becomes member variable of class. struct treated class in c++ if struct definition, can new , structs if class definition. default, member in class private unless list under public. default, member in struct public unless list under private.
![smiley :)](https://forum.arduino.cc/smileys/arduino/smiley.gif)
Arduino Forum > Using Arduino > Programming Questions > structs in libraries
arduino
Comments
Post a Comment