如何在抽象类中实现静态函数?我在哪里实现这个?
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)
首先,该函数需要返回类型.我认为它应该是void.
您可以在源文件中实现它,就像实现任何其他方法一样:
void Item::enableDebug(bool toggle)
{
// Do whatever
}
Run Code Online (Sandbox Code Playgroud)
它是静态的还是Item抽象的类没什么特别的.唯一的区别是您无法访问方法中的this指针(因此也不能访问成员变量).
| 归档时间: |
|
| 查看次数: |
6367 次 |
| 最近记录: |