抽象类中的静态函数

ahe*_*ang 2 c++

如何在抽象类中实现静态函数?我在哪里实现这个?

class Item{
public:
  //
  // Enable (or disable) debug descriptions. When enabled, the String produced
  // by descrip() includes the minimum width and maximum weight of the Item.
  // Initially, debugging is disabled.
  static enableDebug(bool);

};
Run Code Online (Sandbox Code Playgroud)

Tyl*_*nry 5

首先,该函数需要返回类型.我认为它应该是void.

您可以在源文件中实现它,就像实现任何其他方法一样:

void Item::enableDebug(bool toggle)
{
  // Do whatever
}
Run Code Online (Sandbox Code Playgroud)

它是静态的还是Item抽象的类没什么特别的.唯一的区别是您无法访问方法中的this指针(因此也不能访问成员变量).