05_06.cpp
来自「一些C++的课件和实验源代码」· C++ 代码 · 共 37 行
CPP
37 行
// 05_06.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
class point{
private:
int x, y;
void Print(){
cout << "x = " << x << ", y = " << y << endl;
}
public:
point(){x = y = 0;}
friend void setDefault(point pt); // 友元函数
};
void setDefault(point pt)
{
pt.x = pt.y = 10; // 访问私有变量
pt.Print(); // 访问私有函数
}
main()
{
point pt;
setDefault(pt);
pt.setDefault(pt);
getch();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?