VC6不支持"friend"?????
一段非常简单的代码,在VC6下无法通过总说“无法访问私有成员”(大概是这个意思)。但在.NET下可以通过。
#include<iostream>
using namespace std;
class String{
public:
friend ostream& operator<<(ostream& out,String& s);
String(const char* str);
private:
char* str;
};
String::String(const char* s)
{
str=new char[strlen(s)+1];
memcpy(str,s,strlen(s)+1);
}
ostream& operator<<(ostream& out,String & s)
{
cout<<s.str;
return out;
}
void main()
{
String s("hello");
cout<<s;
}
为什么?哪位碰上过相似的问题?