dev/vala/4JavaProgrammers/cpp.cpp

61 lines
718 B
C++

#include <iostream>
using namespace std;
/*
class B {
int *ptr;
};
class A {
public:
int x;
double y;
int *ptr;
};
*/
class A {
std::string _s;
A ();
public:
A (const std::string& s) { _s = s; }
std::string get_s () { return _s; }
std::string set_s (const std::string& s) { _s = s; }
};
int main () {
A a ("0");
A& b = a;
b = a;
cout << "a = " << a.get_s() << endl;
cout << "b = " << b.get_s() << endl;
b.set_s ("1");
cout << "a = " << a.get_s() << endl;
cout << "b = " << b.get_s() << endl;
/* A a;
a.x = 1;
a.y = 2;
a.ptr = &a.x;
A b;
b = a;
cout << a.x << " " << b.x << endl;
cout << a.y << " " << b.y << endl;
cout << a.ptr << " " << b.ptr << endl;
*/
return 0;
}