friend ostream&operator<< //如何定义呀???
#include <stdio.h>
#include <tchar.h>
#include <iostream>
using namespace std;
// TODO: 在此处引用程序需要的其他头文件
class User
{
public:
User(char*pszName,int nAge);
~User(void);
friend ostream&operator<<(ostream&os,const User&user);
private:
string m_strName;
int m_nAge;
};
User::User(char*pszName,int nAge)
{
m_strName = pszName;
m_nAge = nAge;
}
User::~User(void)
{
}
ostream& User::operator<<(ostream&os,const User&user)
{
return os<<user.m_strName<<" "<<user.m_nAge;
}
ostream& operator<<(ostream& os,const User& user)//分开写不要并起来
{
return os<<user.m_strName<<" "<<user.m_nAge;
}