我正在尝试用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();