B
baibaichen
i have written some code to verify how to disable slicing copy
according C++ Gotchas item 30
the follow is my class hierarchy, and note that B is abstract class!!
class B
{
public:
explicit B(INT32 i =0):i_(i){}
virtual ~B(){}
virtual void do_it() = 0;
virtual void pay() const = 0;
protected:
private:
INT32 i_;
};
class D: public B
{
public:
explicit D(INT32 j=0):B(),j_(j){}
virtual void do_it()
{
j_ = 100;
}
virtual void pay() const {}
protected:
private:
INT32 j_;
};
accring to book, the following code can not be compiled, however it can
be compiled in the vc7.1
D d,d1(1);
B *const pb=&d1;
*pb = d; // B is abstract class, and this should be issued a compile
error according to the book
// however it can be compiled in the vc7.1
what's something with me or the book?
thanks
according C++ Gotchas item 30
the follow is my class hierarchy, and note that B is abstract class!!
class B
{
public:
explicit B(INT32 i =0):i_(i){}
virtual ~B(){}
virtual void do_it() = 0;
virtual void pay() const = 0;
protected:
private:
INT32 i_;
};
class D: public B
{
public:
explicit D(INT32 j=0):B(),j_(j){}
virtual void do_it()
{
j_ = 100;
}
virtual void pay() const {}
protected:
private:
INT32 j_;
};
accring to book, the following code can not be compiled, however it can
be compiled in the vc7.1
D d,d1(1);
B *const pb=&d1;
*pb = d; // B is abstract class, and this should be issued a compile
error according to the book
// however it can be compiled in the vc7.1
what's something with me or the book?
thanks