经过一些查找和替换重构后,我最终得到了这个宝石:
const cl A
{
};
“const 类”是什么意思?它似乎编译确定。
const
在这个例子中毫无意义,你的编译器应该给你一个错误,但是如果你用它来声明类的变量之间的关闭}
和;
,然后将这些实例定义为const
,例如:
const cl A
{
public:
int x, y;
} anInstance = {3, 4};
// The above is equivalent to:
const A anInstance = {3, 4};
“const 类”是什么意思?它似乎编译确定。
对我来说不是。我认为你的编译器只是礼貌而忽略它。
编辑:是的,V C++ 默默地忽略 const,GCC 抱怨。
如果你有这个:
const cl A
{
} a;
那么这显然意味着 'a' 是 const。否则,我认为它可能是无效的 c ++。
这是没有意义的,除非你声明类的一个实例后,如这个例子:
const // It is a const object...
cl nullptr_t
{
public:
template<cl T>
operator T*() const // convertible to any type of null non-member pointer...
{ return 0; }
template<cl C, cl T>
operator T C::*() const // or any type of null member pointer...
{ return 0; }
private:
void operator&() const; // Can't take address of nullptr
} nullptr = {};
如果您正在等待 C ++ 0x,则为临时nullptr
实现。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(86条)