Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Vector {
- private:
- double *vec;
- public:
- Vector() : vec(NULL) {}
- Vector(double a, double b)
- {
- vec = new double[2];
- vec[0] = a;
- vec[1] = b;
- }
- ~Vector() {
- if (vec) {
- delete[] vec;
- vec = NULL;
- }
- }
- void disp() {
- if (vec) cout << vec[0] << " " << vec[1] << endl;
- else cout << "NULL" << endl;
- }
- Vector & operator=(Vector &p) {
- if (p.vec) {
- if (this->vec) {
- vec[0] = p.vec[0];
- vec[1] = p.vec[1];
- return *this;
- }
- else {
- this->vec = new double[2];
- vec[0] = p.vec[0];
- vec[1] = p.vec[1];
- return *this;
- }
- }
- else {
- if (this->vec) {
- delete[] this->vec;
- this->vec = NULL;
- return *this;
- }
- } return *this;
- }
- Vector operator*(Vector &(&p)) {
- return *this;
- }
- };
- int main()
- {
- Vector a(1, 2), b(2, 3), c;
- a.disp();
- b.disp();
- c.disp();
- c = a;
- c.disp();
- c=a*(&b);
- c.disp();
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment