为什么 C++11 允许抽象的最终类
Why does C++11 allow abstract final classes?
为什么编译下面的代码?我正在使用视觉工作室;我不确定它是否只是不符合标准,或者是否有充分的理由允许这样做,或者它只是语言中的疏忽。
struct Base {
virtual void foo() = 0;
};
// since this class is final and abstract, it can never be
// instantiated - why isn't its very declaration an error?
struct Derived final : Base {};
int main() {
//Derived derived; // this IS an error, but relies on someone trying
// to instantiate the class, and the error is at the site
// of instantiation, not the class itself
}
因为没有充分的理由禁止它。它似乎不是很有用,但是如果您想要一个无法实例化但仍提供静态成员函数的结构,这是实现此目的的一种方法。(私有构造函数可能是实现此目的的更好方法。
让Java和朋友们来取缔这种事情:为什么公共抽象最终类在语法上无效?
相关文章:
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 抽象类错误,请参阅声明" "是抽象的
- C++抽象的字节序是中立的吗?
- MacOS 上的 Xcode 11 项目不在一个函数中使用 sin 和 cos:未定义的符号"___sincosf_stret"
- 如何删除 vsCode 中的 C++ 11 扩展警告
- 带有void类型和参数的C++11模板专用化
- Centos6 gcc6:编译简单的 c++11 测试文件时,默认的 ABI 不拾取
- 相当于旧版C++的 C++11 unordered_map
- 观察者模式:为什么主题应该是抽象的?
- 具有抽象工厂的派生类的 C++11 单例
- 标准向量之上的 C++11 包装类
- 简单的 C++11 哈希函数无法编译
- 这被认为是有效的C 11还是C 14?还是GCC/Clang弄错了
- 派生类仍然是抽象的
- 将信号连接到QT5中的C 11 lambdas
- 确保课程不是抽象的
- 为什么我的课被认为是抽象的
- 基类为抽象的 ADT 数组
- 具有类成员默认值的 C++11 默认构造函数行为
- 为什么 C++11 允许抽象的最终类