gpt4 book ai didi

c++ - 抽象类中的静态函数

转载 作者:搜寻专家 更新时间:2023-10-31 00:23:01 25 4
gpt4 key购买 nike

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

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);

};

最佳答案

首先,该函数需要一个返回类型。我假设它应该是 void

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

void Item::enableDebug(bool toggle)
{
// Do whatever
}

它是静态的或 Item 类是抽象的没有什么特别之处。唯一的区别是您无权访问方法内的 this 指针(因此也无权访问成员变量)。

关于c++ - 抽象类中的静态函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2642321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com