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


is possible use class return type of class method (ergbnisausfortran) this:

class ergbnisausfortran { public:    ergbnisausfortran(); private:    int var_a;    int var_b ;   public:     int getvar_a() const { return var_a; }    int getvar_res() const { return var_res; }     void setvar_res(int input)      {var_res = input;}    void setvar_a(int input)        {var_a = input;}     ergbnisausfortran calculateresults(eingabewerte ein);     }; 

absolutely, possible. quite common - example, factory method pattern can implemented within single class, in case member functions returning instances of class of members. common situation when done immutable classes producing modified versions of themselves.

although can in situations, there may situations when should not it, opting creating separate class function returning instances of class. main criterion whether makes sense logical point of view.


Comments