【问题标题】:Non-virtual function declaration ends with =0非虚函数声明以 =0 结尾
【发布时间】:2015-06-10 07:07:32
【问题描述】:
string foo() const = 0;

这个函数声明到底是什么意思?特别是,'=0' 有什么好处,因为该函数没有声明为虚拟函数?

【问题讨论】:

  • 如果foo 不是虚拟的,这将无效。这条线本身并不能证明 foo 也是非虚拟的。
  • @chris:谢谢! 'foo' 没有在其他任何地方声明为虚拟的;我已经怀疑这没有意义,因为我也尝试用谷歌搜索,但没有任何结果。我没有准备好编译器,所以我想我会在这里问

标签: c++ syntax


【解决方案1】:

=0 是函数是纯虚函数的语法。据我所知,声明之前还需要关键字 virtual。

更多关于这里的阅读:What does it mean to set the declaration of a function equal to 0? How can you assign an integer to a function?

Difference between a virtual function and a pure virtual function

【讨论】:

    猜你喜欢
    • 2011-02-01
    • 1970-01-01
    • 2020-10-19
    • 2020-03-22
    • 2011-11-23
    • 2014-03-29
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多