Last active
August 29, 2015 14:22
-
-
Save toanalien/6af3d7434ea216538b2d to your computer and use it in GitHub Desktop.
constructor & deconstrutor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class PhanSo | |
{ | |
private: | |
int ts, ms; | |
public: | |
PhanSo (int ts = 0, int ms = 1); | |
PhanSo operator +(PhanSo); | |
void out(); | |
}; | |
PhanSo::PhanSo(int ts, int ms) | |
{ | |
this->ts = ts; | |
this->ms = ms; | |
} | |
PhanSo PhanSo::operator+(PhanSo ps) | |
{ | |
return PhanSo(ts += ps.ts, ms += ps.ms); | |
} | |
void PhanSo::out() | |
{ | |
cout << ts << "\t" << ms << endl; | |
} | |
int main() | |
{ | |
PhanSo a, b(3, 4), c(2, 5); | |
//a = b + c; | |
//a.out(); | |
a = b + 3; | |
a.out(); | |
system("pause"); | |
//a = 5 + c; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment