标签:world cat char std public point printf hello argv
// 友元函数.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
class Student{
public:
	Student(int x,int y){
		this->x=x;
		this->y=y;//好像用this的时候只能用指针的方式去引用类的成员
	}
private :
	int x;
	int y;
friend void print(const Student& stu);
};
void print(const Student& stu){//由于友元函数不是类的成员函数,所以在定义友元方法时按照普通的方法去定义,不用写成类名::方法名的形式
		printf("%d\n",stu.x);
		printf("%d\n",stu.y);
	}
int main(int argc, char* argv[])
{	
	Student stu(5,6);
	print(stu);
	
	printf("Hello World!\n");
	return 0;
}
//注意:友元函
标签:world cat char std public point printf hello argv
原文地址:http://www.cnblogs.com/zhuh102/p/6028829.html