代码如下:
#include "stdafx.h"
#include "iostream.h"
class date{
public:
data();
virtual void show(){};}
show(data* d){
d->show();
}
class dataInt:public data{
 private;
 int val;
public:
 dataInt(int& i){val=i;}
 virtual void show(){
 cout<<"the integer number is:"<<val<<endl;
 }
 
 class dataFloat:public data{
 private;
 int val;
public:
 dataFloat(float& f){val=f;}
 virtual void show(){
 cout<<"the float number is:"<<val<<endl;
 } class dataChar:public data{
 private;
 int val;
public:
 dataChar(int& c){val=c;}
 virtual void show(){
 cout<<"the character is:"<<val<<endl;
 }
 };int main(int argc, char* argv[])
{float ftest=100.0;
int iTest=25;
char cTest="Z";
dataFloat f(fTest);
dataInt i(iTest);
dataChar c(cTest);
show(f);
show(i);
show(c);
return 0;
}错误信息:C:\Documents and Settings\gaoy\My Documents\3\3.cpp(9) : error C2065: 'data' : undeclared identifier
C:\Documents and Settings\gaoy\My Documents\3\3.cpp(9) : error C2065: 'd' : undeclared identifier
C:\Documents and Settings\gaoy\My Documents\3\3.cpp(9) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
C:\Documents and Settings\gaoy\My Documents\3\3.cpp(12) : error C2516: 'data' : is not a legal base class
C:\Documents and Settings\gaoy\My Documents\3\3.cpp(13) : error C2320: expected ':' to follow access specifier ';'
C:\Documents and Settings\gaoy\My Documents\3\3.cpp(21) : error C2516: 'data' : is not a legal base class
C:\Documents and Settings\gaoy\My Documents\3\3.cpp(22) : error C2320: expected ':' to follow access specifier ';'
C:\Documents and Settings\gaoy\My Documents\3\3.cpp(30) : error C2516: 'data' : is not a legal base class
C:\Documents and Settings\gaoy\My Documents\3\3.cpp(31) : error C2320: expected ':' to follow access specifier ';'
C:\Documents and Settings\gaoy\My Documents\3\3.cpp(52) : fatal error C1004: unexpected end of file found
Error executing cl.exe.