I’m trying to create an object which I want to populate inside a switch-case, but it’s out of my knowledge scope.
I have these constructors:
cObj::cObj()
{
}
cObj::cObj(std::string filename)
{
//...
}
So, basically I want to call following method, create a pointer to the object, and populate it inside of my switch-case:
void someThing() {
cObj myObj();
switch (someValue)
case 0:
myObj("/some/path");
break;
...
}
I assume my constructor is wrong since it does not really work.
How can I accomplish this?
When you create your object in this line
(btw. you probably don’t want these parentheses. You want to create an object, not declare a function).
you call the constructor. You can not call it again in switch statement.
You could create a separate method:
and use it like that:
I’m not sure what you’re trying to do, but maybe better way would be to first determine what the filepath is and then create the object?
You could also create a function that would make the decision what path to use and return the object: