由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 为啥 const Base cb 要求Base() {} 而 const vBase vb 不呢?
相关主题
C++弱问c++问题,请高人指点迷津,c++ faq lite的一个例子
C++ questionC++ (direct vs indirect initialization)
关于C/C++里的Static variable的memory allocation/initializa一个C++ 的问题
question about const referenceWhat're the three types of memory allocated for C++ variables?
How to initialize object in constructor?c++ initialize struct
const object问个copy constructor的问题
两个继承问题thrust, about the initialization of POD
Re: VC里面的stl支持是不是很弱?再问C++初始化问题。
相关话题的讨论汇总
话题: base话题: const话题: vbase话题: class话题: object
进入Programming版参与讨论
1 (共1页)
i**p
发帖数: 902
1
#include
using namespace std;
class Base {
public:
void f() const {}
};
class vBase {
public:
virtual void f() const {}
~vBase() {}
};
main() {
Base b;
//! const Base cb; // To enable it, add Base() {} to the class
const vBase vb;
const vBase vcb;
}
p***o
发帖数: 1252
2
Your compiler is buggy. Neither VC nor gcc requires a ctor in Base.

【在 i**p 的大作中提到】
: #include
: using namespace std;
: class Base {
: public:
: void f() const {}
: };
: class vBase {
: public:
: virtual void f() const {}
: ~vBase() {}

l*********s
发帖数: 5409
3
the standard requires custom ctor for const class, probably thee compiler
has a bug to let you go through with vCB
quote/
8.5]
9. If no initializer is specified for an object, and the object is of
(possibly cv-qualified) non-POD class type (or array thereof), the object
shall be default-initialized; if the object is of const-qualified type,
the underlying class type shall have a user-declared default constructor.
Otherwise, if no initializer is specified for an object, the object and
its subobjects, if any, have an indeterminate initial value 90) ; if the
object or any of its subobjects are of const-qualified type, the program
is ill-formed.
1 (共1页)
进入Programming版参与讨论
相关主题
再问C++初始化问题。How to initialize object in constructor?
question regarding const functionconst object
C++ 中 myobject * a =new myobject[n] 的问题两个继承问题
Global(static) variable initialization questionRe: VC里面的stl支持是不是很弱?
C++弱问c++问题,请高人指点迷津,c++ faq lite的一个例子
C++ questionC++ (direct vs indirect initialization)
关于C/C++里的Static variable的memory allocation/initializa一个C++ 的问题
question about const referenceWhat're the three types of memory allocated for C++ variables?
相关话题的讨论汇总
话题: base话题: const话题: vbase话题: class话题: object