为什么他说我不能访问基类中的函数呢?
#include <iostream>
using namespace std;
class Base{
public:Base (){cout<<"Base被构造"<<endl;}
~Base (){cout <<"Base 被析构"<<endl;}
void fn1(char *c);
void fn2(int *b);
};
void Base::fn1(char *c)
{cout<<"你输入的字符是:"<<endl;}
void Base::fn2(int *b)
{cout <<"你输入数字是:"<<endl;}
class Drived:private Base
{public :Drived(){cout<<"Drived 被构造:"<<endl;}
~Drived(){cout<<"Drived被析构:"<<endl;}
};
void main()
{char c[10];
int b[10];
cout<<"enter charcter you want to input:"<<endl;
cin>>c;
cout <<"enter the number you want to input:"<<endl;
for(int i=0;i<=9;i++)
cin>>b[i];
Drived drived;
drived.fn1(c);
drived.fn2(b);
}
错误调试:
--------------------Configuration: 11 - Win32 Debug--------------------
Compiling...
11.cpp
D:\学习文件\CL\7-9\11\11.cpp(32) : error C2248: 'fn1' : cannot access public member declared in class 'Base'
D:\学习文件\CL\7-9\11\11.cpp(6) : see declaration of 'fn1'
D:\学习文件\CL\7-9\11\11.cpp(33) : error C2248: 'fn2' : cannot access public member declared in class 'Base'
D:\学习文件\CL\7-9\11\11.cpp(7) : see declaration of 'fn2'
执行 cl.exe 时出错.
11.obj - 1 error(s), 0 warning(s)