当把一个派生类对象赋给一个基类对象时,会发生对象切割。(另外用基类对象强制转换派生类对象也会) 对象切割会发生什么呢? #include <iostream> using namespace std; class CShape { public: CShape () { m_color=0; } ~CShape(){} virtual void draw() { cout<<"This is a shape!"<<endl; cout<<m_color<<endl; } double m_color; }; class CRect: public CShape { public: CRect() { m_width=5; m_height=4; m_color=1; } ~CRect(){}; double size() { return m_width*m_height; } virtual void draw() { cout<<"This is a rect!"<<endl; cout<<m_color<<endl; } double m_width; double m_height; }; int main(int argc, char* argv[]) { CShape shp; CRect rect; shp = rect; shp.draw(); ((CShape)rect).draw();//注意此行 CShape *pShape=new CShape(); *pShape=rect;//对象切割 pShape->draw(); pShape=▭//多态实现, p