Art C Art C - 3 months ago 10
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

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
{
    //....
public:
   A someFunction();
   //.....
}

//implementation:
A A::someFunction()
{
    //Code....
}