Just a quick question.
I’ve written some code that returns a custom class Command, and the code I’ve written seems to work fine. I was wondering if there are any reasons that I shouldn’t be doing it this way. It’s something like this:
Command Behavior::getCommand ()
{
char input = 'x';
return Command (input, -1, -1);
}
Anyway, I read that constructors aren’t meant to have a return value, but this works in g++.
Thanks for any advice,
Rhys
The constructor itself doesn’t have a return value. What this does is constructs a temporary
Commandobject and returns the constructed objet to the caller. It’s effectively the same as if you said:It will work on any C++ compiler.