Hand a struct member to a function
howdy all,
i'm new c++, hope isn't stupid question. apologies in advance if that's case!
i have struct looks :
i use struct in function :
is possible hand struct member in don't have use ugly if loop in function? stripped down version - there many more values in full deal, it's uglier.
i'm hoping end function looking :
any thoughts or different approaches more welcomed.
cheers,
doug.
i'm new c++, hope isn't stupid question. apologies in advance if that's case!
i have struct looks :
code: [select]
struct config_t
{
unsigned int probe1value;
unsigned int probe2value;
}configuration;
i use struct in function :
code: [select]
void myfunction(int probe, int value)
{
if(probe==1)
{
configuration.probe1value = value;
}
else if(probe==2)
{
configuration.probe2value = value;
}
}
is possible hand struct member in don't have use ugly if loop in function? stripped down version - there many more values in full deal, it's uglier.
i'm hoping end function looking :
code: [select]
void myfunction(<whateverthetypeis?> structmember, int value)
{
structmember = value;
}
any thoughts or different approaches more welcomed.
cheers,
doug.
you can pass pointer (struct config_t *p) structure or pass reference (struct config_t &p), not make copy of data , allows function modify original data.
you can pass data structure (struct config_t), in case copy of data created locally function.
i define type structure (typedef), make usage bit less clunky , more obvious.
you can pass data structure (struct config_t), in case copy of data created locally function.
i define type structure (typedef), make usage bit less clunky , more obvious.
Arduino Forum > Using Arduino > Programming Questions > Hand a struct member to a function
arduino
Comments
Post a Comment