C++ says that we can’t return anything from the constructor? What is the historical reason behind it?
Why did Bjarne disallow contructors to return something unlike any other member function?
C++ says that we can’t return anything from the constructor? What is the historical
Share
Because when an object is being constructed in a
newstatement or in a variable initializer, the object that is returned is that new object which is being constructed. What would you ever do with an object returned from a constructor? It couldn’t ever be returned anywhere; it’s the object being constructed that is returned. That object has already been (partially) created before the constructor is called (otherwise, the constructor wouldn’t have an object to work on), and it must be what is returned from the constructor, so there is no point in making the user return it or allow them to confuse themselves by trying to return something different.