Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

types

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.

like image 723
Art C Avatar asked Nov 15 '25 10:11

Art C


1 Answers

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....
}
like image 184
Arnav Borborah Avatar answered Nov 17 '25 00:11

Arnav Borborah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!