Skip to content

Instantly share code, notes, and snippets.

@iamandrewluca
Created January 23, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamandrewluca/0dee4b8b84f9f38e1328 to your computer and use it in GitHub Desktop.
Save iamandrewluca/0dee4b8b84f9f38e1328 to your computer and use it in GitHub Desktop.
#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