class point
{
//public:
void output()
{
cout << x <<endl << y <<endl;
}private:
int x;
int y;};
public 注释掉就不可以访问,这是为什么?不是都在类的内部吗?
{
//public:
void output()
{
cout << x <<endl << y <<endl;
}private:
int x;
int y;};
public 注释掉就不可以访问,这是为什么?不是都在类的内部吗?
解决方案 »
- 关于多线程
- CDialog如何用鼠标调整大小
- =====女同胞进来!为了活跃VC版气氛,欲招收女性斑竹数名,详情入内======
- 请教GPS通讯协议NMEA的一个问题
- 关于CScrollView类的滚动条问题??????50分
- 命令补齐全都有,居然还会报错!----在线等待!
- GetTextExtentPoint函数的效率怎么这么低?请高手帮忙
- 如何打开并读取txt中的数据,并附到数组中
- 关于匈牙利命名法则!
- CRITICAL_SECTION 类型中的 LockCount 为什么都是负数
- vc 做word 开发插入图片的一个问题
- 两张具有不同调色板的256色的图像,如何设计新的调色板使得他们半透明混合后的颜色尽量不失真呢?
在class里面,默认是private
在struct里面,默认是public
结构的成员变量和函数默认是public
//私有成员函数只能在类里面访问
#include "stdafx.h"
#include <iostream>
using namespace std;class A
{
public:
A(int a,int b){x=a;y=b;}
//public:
private: void output2()
{
cout << x <<endl<<y <<endl;
}private:
int x;
int y;
};
int _tmain(int argc, _TCHAR* argv[])
{
A a(3,6);
a.output2();
system("pause");
return 0;
}
1.output可以访问x 类自身的函数可以访问私有成员
2.外面的代码不可以使用output函数,外部代码不能使用类的私有函数