Is it better to do:
class Foo{
std:string option1(MY_ENUM type){
static const std:string f1 = "a";
static const std:string f2 = "b";
static const std:string f3 = "c";
// ...
switch (type) {
case (TYPE_1):{
return f1;
break;
}
case (TYPE_2):{
return f2;
break;
}
// ...
}
}
Or do this:
class Foo {
private:
const std:string f1 = "a";
const std:string f2 = "b";
const std:string f3 = "c";
public:
std:string option1(MY_ENUM type){
// ...
switch (type){
case (TYPE_1):{
return f1;
break;
}
case (TYPE_2):{
return f2;
break;
}
// ...
}
}
Likewise I would do something similar to convert the enum to the string. Is it better to keep the strings as static const within the function, or as private within the class ? - No one else is going to edit the class but me. - It doesn't really matter if any other functions inside the class know what the values of the strings are, and since it is const they can't modify it anyway.
Which is cheaper and has less overhead at runtime and during compilation ? Which is a better practice ?