当前位置: 动力学知识库 > 问答 > 编程问答 >

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.

网友答案:

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....
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: