is it possible to use a class as a return type of a the own method

时间:2015-05-08 09:59:00

标签: c++ class types return

Is it possible to use a class as a return type of a class method (ErgbnisAusFortran) like this:

WSD

1 个答案:

答案 0 :(得分:2)

Absolutely, this is possible. This is also quite common - for example, Factory Method pattern can be implemented within a single class, in which case member functions would be returning instances of the class of which they are members. Another common situation when this is done is immutable classes producing modified versions of themselves.

Although you can do it in nearly all situations, there may be situations when you should not do it, opting for creating a separate class with a function returning instances of your class. The main criterion is whether it makes sense from a logical point of view.

相关问题