Skip to content

Instantly share code, notes, and snippets.

@toanalien
Last active August 29, 2015 14:22
Show Gist options
  • Save toanalien/6af3d7434ea216538b2d to your computer and use it in GitHub Desktop.
Save toanalien/6af3d7434ea216538b2d to your computer and use it in GitHub Desktop.
constructor & deconstrutor
#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