赋值符号是什么意思

发布于 2024-09-28 09:25:16 字数 132 浏览 0 评论 0原文

我不明白下面一行中的分配。我认为,setBit是一个函数,但它被分配了一个值。

bool setBit(const unsigned int which) = 0;

i don't understand assignment in the following line. i think, setBit is a function but it's assigned a value.

bool setBit(const unsigned int which) = 0;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何止钟意 2024-10-05 09:25:16

这不是任务。它表示纯虚函数。具有一个或多个纯虚函数的类称为“抽象类”,并且不能单独实例化。派生类必须实现该函数,以避免本身成为抽象类。所以这里=0的意思是“我的派生类将提供这个功能”。

It's not assignment. It indicates a pure virtual function. A class with one or more pure virtual functions is called an "abstract class", and cannot be instantiated on its own. Derived classes must implement the function in order to avoid being abstract classes themselves. So the meaning of =0 here is, "my derived classes will provide this function".

§对你不离不弃 2024-10-05 09:25:16

这是一个虚函数。当您声明一个函数并将其分配为 0 时,您正在创建一个没有实现的函数

当您继承此类时,您可以为该函数创建一个具体的实现

This is a virtual function. when you declare a function and assign it 0 you are creating a function without an implementation

When you inherit this class you can them create a concrete implementation for this function

望喜 2024-10-05 09:25:16

我假设您错过了 bool 之前的 virtual 一词。它是类中抽象函数的声明。在 C++ 中,抽象函数称为纯虚函数,您可以通过在声明末尾指定 = 0 来告诉编译器它是抽象函数。

I assume that you missed the word virtual before bool. It's the declaration of an abstract function in a class. In C++ abstract functions are called pure virtual functions and you tell the compiler that it is abstract by specifying = 0 at the end of the declaration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文