![]() |
#2
Jonny02012018-04-17 19:16
|

#include <iostream>
using namespace std;
class A
{
public:
void print(int)
{
cout << "haha" << endl;
}
};
class B : protected A
{
public:
void print(int, int)
{
cout << "fuck" << endl;
}
void likeit(A &a);
friend void damnit(A &a);
};
void damnit(A &a)
{
cout << "0_0" << endl;
}
int main()
{
B b;
damnit(b);
b.likeit(b);
system("pause");
return 0;
}
using namespace std;
class A
{
public:
void print(int)
{
cout << "haha" << endl;
}
};
class B : protected A
{
public:
void print(int, int)
{
cout << "fuck" << endl;
}
void likeit(A &a);
friend void damnit(A &a);
};
void damnit(A &a)
{
cout << "0_0" << endl;
}
int main()
{
B b;
damnit(b);
b.likeit(b);
system("pause");
return 0;
}
程序如上:运行结果错误,但是C++ primer P544 又有如下片段,按照->指向的那一条应该允许访问才对,请问是我理解哪里有误吗?
只有本站会员才能查看附件,请 登录