- 论坛徽章:
- 0
|
私有函数能调public的函数吗?
私有的函数可以调用公有的成员
test.h
class X{
int a;
int getb(int);
public:
X();
~X();
int geta(int);
int getc(int);
};
test.cpp
#include <iostream>;
#include "test1.h"
using namespace std;
X::X()
{
a=10;
cout << "Create X" <<endl;
}
X::~X()
{
cout << "destroy X" <<endl;
}
int X::geta(int i)
{
cout <<"run geta"<<endl;
a=i;
}
int X::getb(int i)
{
cout <<"run getb"<<endl;
X::geta(i);
}
int X::getc(int i)
{
cout <<"run getc"<<endl;
getb(i);
}
int main (int argc, char *argv[])
{int b;
{X x;
b=8;
x.getc(b);
}
cout << "ress ENTER to continue..." << endl;
cin.get();
return 0;
}
结果:
create X
run getc
run getb
run geta
Destroy X
Press ENTER to continue. |
|