No return value for constructors?

Hi Ben,

In lecture 28 we create a constructor for our FBullCowGame class. In previous lectures you mentioned you ALWAYS like to have a return statement (even for voids). With the class constructor type used here, this is not the case.

My question regarding this is:
Is the constructor type even capable of returning a value, and if so, is it ever used? Perhaps in a similar way int main returns 0 to tell the system it has exited correctly.

Thanks in advance!

Just like a void function it can’t return a value but you can have a return statement in it. i.e.

struct Foo()
    Foo() { return; }

And just like a void function, you don’t have to put it. IMO, putting a return in either when it’s not needed is rather redundant.

1 Like

Thanks for the quick and coherent answer!

This was my assumption, thanks for confirming it for me.