本人小白,http://blog.sina.com.cn/s/blog_470740c80100y45c.html
按照此方法并没有解决,求助各位前辈
多贴点代码看看。
你是不是Animal构造没有实现?
****//
// main.cpp
// 虚函数和纯虚函数
//
// Created by 梁煜其 on 16/5/13.
// Copyright © 2016年 梁煜其. All rights reserved.
//
#include
#include
#include
using namespace std;
/**
/**
class Dog : public Animal
{
public:
// 默认构造函数
Dog();
// 含参构造函数
Dog(string name)
{
m_strName = name;
cout << "Dog" << endl;
}
// 虚析构函数
virtual ~Dog()
{
cout << "~Dog" << endl;
}
// 虚成员函数eat()
virtual void eat(){cout << "Dog--" << m_strName << " -- eat" << endl;}
// 虚成员函数move()
virtual void move(){cout << "Dog--" << m_strName << " -- move" << endl;}
public:
// 数据成员
string m_strName;
};
int main(void)
{
// 通过动物类实例化狗类
Animal *p=new Dog("狗");
// 调用成员函数
p->eat();
p->move();
// 释放内存
delete p;
p=NULL;
return 0;
}