会员请求,非类型<>错误

时间:2016-08-05 07:03:35

标签: c++

我正在尝试用c ++实现策略设计模式。这是我的代码 -

#include <iostream>
using namespace std;

class Transport
{
    public:
        virtual void Go()=0;
};


class car: public Transport
{
    private:
         void Go()
        {
            cout << "car" << endl;
        }
};

class bus: public Transport
{   
    bus()
    {

    }
    private:
        void Go()
        {
            cout << "bus" << endl;
        }
};
int main()
{
    bus obj();
    obj.Go();

}

但是我收到以下错误 -

error: request for member ‘Go’ in ‘obj’, which is of non-class type ‘bus()’
  obj.Go();

0 个答案:

没有答案