Art C Art C - 1 year ago 56
C++ Question

C++ Return a Type of object in a method of the same class

To clarify I was wondering how to return the type of a class within the class definition.

Even though an answer was given I ended up reverting back to using a virtual function, which kind of made more sense in the long run.

Sorry for the confusion.

Answer Source

You could write A as the return type? Classes define user-defined types, meaning they can be used as return types. Sorry, if I misinterpreted your question though, and if there is an error, please point it out. Anyways, here is the code below:

class A
   A someFunction();

A A::someFunction()