Created
January 23, 2015 14:17
-
-
Save iamandrewluca/0dee4b8b84f9f38e1328 to your computer and use it in GitHub Desktop.
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> | |
class Punct | |
{ | |
private: | |
float x; | |
float y; | |
public: | |
Punct(): x(.0f), y(.0f) { std::cout << "default" << std::endl; } | |
Punct(float _x, float _y): x(_x), y(_y) { std::cout << "general" << std::endl; } | |
Punct(const Punct& obj): x(obj.x), y(obj.y) { std::cout << "copy" << std::endl; } | |
~Punct() { std::cout << "destructor" << std::endl; } | |
int getX() { return x; } | |
int getY() { return y; } | |
Punct& operator ++ () | |
{ | |
std::cout << "suffix" << std::endl; | |
++x; | |
++y; | |
return *this; | |
} | |
Punct operator ++ (int) | |
{ | |
std::cout << "postfix" << std::endl; | |
Punct p(*this); | |
++(*this); | |
return p; | |
} | |
Punct& operator = (const Punct& obj) | |
{ | |
std::cout << "equal" << std::endl; | |
x = obj.x; | |
y = obj.y; | |
} | |
}; | |
int main(int argc, char **argv) | |
{ | |
Punct p1(1, 2); | |
Punct p2 = p1++; | |
std::cout << p2.getX() << " " << p2.getY() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment