小编Lat*_*tte的帖子

您可以声明一个成员函数并使它们执行不同的操作吗?

我尝试了很多方法来解决这个问题,但是没有一个起作用。我想要达到的目标是这个。

我有这样的课。

class Auton {
  public:
    int slot;
    const char * name;
    void run();
};
Run Code Online (Sandbox Code Playgroud)

我要做的是使run函数执行不同的操作。例如 -

// The code below doesn't work, unfortunately :(

Auton one;
void one::run() {
  // Do something here
}

Auton two;
void two::run() {
 // Do something different here
}
Run Code Online (Sandbox Code Playgroud)

这可能吗?

c++

1
推荐指数
1
解决办法
97
查看次数

标签 统计

c++ ×1