vs code下开发C++时virtual失效不起作用(macOs)




```#include<iostream>
using namespace std;

//动物类
class Animal
{
public:
virtual void speak()
 {
     cout<<"动物在说话"<<endl;
 }
};

//猫类
class Cat: public Animal
{
public:
   void Speak()
   {
       cout<<"小猫在说话"<<endl;
   }
};

void doSpeak(Animal & animal)
{
    animal.speak();


}

void test01()
{
    Cat cat;
    doSpeak(cat);
}

int main()
{
test01();


    system("pause");

    return 0;
}
void doSpeak(Animal  *animal)
{
    animal->speak();
 
 
}
 
void test01()
{
    Cat *pCat = new Cat;
    doSpeak(pCat);
}


动物在说话
sh: pause: command not found
最后的输出结果还是这个,virtual丝毫没起作用