[ create a new paste ] login | about

Link: http://codepad.org/ZR6aBfmD    [ raw code | output | fork ]

C++, pasted on Mar 31:
#include <iostream>
using namespace std;

class First
{
int x;
public:
void setx(int var) {
x = var;
}
friend int getx(First obj) { //定義 friend 函數
return obj.x;
}
};

class Second
{
int y;
public:
void sety(int var) {
y = var;
}
void showxy(First obj) {
cout << "x = " << getx(obj) << endl; //呼叫 friend 函數
cout << "y = " << y << endl;
}
};

int main()
{ 
First A;
Second B;
A.setx(10);
B.sety(20);
B.showxy(A); 
system("PAUSE");
return 0; //成功結束程式
}


Output:
1
2
3
4
x = 10
y = 20

Disallowed system call: SYS_fork


Create a new paste based on this one


Comments: