注册 登录
编程论坛 C++教室

高高手帮忙看一下,这样的提示是什么意思?

棉雨 发布于 2011-06-26 09:34, 421 次点击
#include<iostream>
typedef int datatype;
using namespace std;
class A
{
protected:
 datatype a,b;
public:
 A(datatype c,datatype d):a(c),b(d)
 {
 }
 virtual void set()=0;
 virtual void show()=0;
};
class B:public A
{
public:
 B(datatype c,datatype d):A(c,d)
 {
 }
 void set()
 {
 cout<<"please input the stutistic:"<<endl;
 cin>>a>>b;
 }
 void show()
 {
 cout<<"the stutistic is:"<<endl;
 cout<<a<<" "<<b<<endl;
 }
};
int main()
{
 B b(1,2);
 b.show();
   A a[]={b};
 a[0].set();
 a[0].show();
 return 0;
}
我调试的时候没有错误,但运行的时候出现这样的提示:
obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall A::show(void)" (?show@A@@UAEXXZ)
obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall A::set(void)" (?set@A@@UAEXXZ)
我想问一下这个是什么意思?为什么会出现这样的信息?
2 回复
#2
rjsp2011-06-26 11:13
代码改为
    A* a[] = { &b };
    a[0]->set();
    a[0]->show();

因为A是个纯虚类,无法被实例化,当然也就不可能声明其数组
#3
棉雨2011-06-26 11:20
回复 2楼 rjsp
后来我去查了一下,说,有纯虚函数的类是不可能生成类对象的,如果没有纯虚函数则可以.
1