我想知道這是什麼指針 Bird * object = new Cat; 它是指向一個Bird類型還是Cat類型的對象?新的類和對象的使用指針
class Bird
{
public:
Bird() { cout << "Bird's constructor\n"; }
void fly() { cout << "Bird's Fly\n"; }
void print() { cout << "Bird's print\n"; }
~Bird() { cout << "Bird's destructor\n"; }
};
class Cat : public Bird
{
public:
Cat() { cout << "Cat's constructor\n"; }
void fly() { cout << "cat's Fly\n"; }
void printCat() { cout << "Cat's print\n"; }
~Cat() { cout << "Cat's destructor\n"; }
};
int main()
{
Bird* object = new Cat;
return (0);
}
它指向'Cat'對象內的'Bird'基類子對象。 – 2014-09-03 00:07:19
這是一隻[飛貓](http://therealweeklyshow.files.wordpress.com/2012/06/flying-cat1.jpg) – quantdev 2014-09-03 00:07:39
Bird * object = new Cat;很可能是最糟糕的示例代碼! – 2014-09-03 00:08:44