variable return type in c++ class

前端 未结 7 1740
花落未央
花落未央 2021-01-25 08:33

i have a class with the following structure:

class myClass
{
    private:
        int type;
        classOne objectOne;
        classTwo objectTwo;
    public:
          


        
7条回答
  •  旧时难觅i
    2021-01-25 08:48

    If they're completely different structures, with no common base then an alternative way you can return them from the same function is to use void*.

    However that's bad form in C++, usually indicating a design failure - either use two different functions, or use a common base class.

    It's apples and oranges. If you put an apple into an recipe that calls for an orange it won't be the same recipe anymore.

提交回复
热议问题