问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
#include<iostream>
using namespace std;
#include<string>
class Animal
{
virtual void speak()
{
cout << "动物在说话" << endl;
}
};
class Cat :public Animal
{
public:
Cat(char* name)
{
this->m_name = new char[strlen(name) + 1];
strcpy(this->m_name, name);
}
void speak()
{
cout << "小猫在说话" << endl;
}
char* m_name;
~Cat()
{
if (this->m_name != NULL)
{
delete[] this->m_name;
this->m_name = NULL;
}
}
};
void test01()
{
Animal* animal = new Cat("Tom");
}
int main()
{
return 0;
}
```c++
```