为什么不能创建空类的const对象 [英] why a const object of an empty class cant be created
本文介绍了为什么不能创建空类的const对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <iostream>
class A {
public:
void foo() const {
std::cout << "const version of foo" << std::endl;
}
void foo() {
std::cout << "none const version of foo" << std::endl;
}
};
int main()
{
A a;
const A ac;
a.foo();
ac.foo();
}
上面的代码无法编译,有人可以告诉我为什么?
The above code can't be compiled, could anyone of you tell me why?
推荐答案
您需要对其进行初始化。 此规范存在已知问题
You need to initialize it. This is a known problem with the spec.
这篇关于为什么不能创建空类的const对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文