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. |
|