ClassOne classOne;
//Figure #1 class ClassOne { } //Figure #2 class ClassOne { ClassOne(int, int); } //Figure #3 class ClassOne { ClassOne(const ClassOne&); } //Figure #4 class ClassOne { ClassOne(ClassOne&&); } //Figure #5 class ClassOne { //ctor(V) //ctor(const ClassOne&) //ctor(ClassOne&&) //ClassOne& operator=(const ClassOne&) //ClassOne& operator=(ClassOne&&) } //Figure #6 class ClassOne { ... ClassOne(int x, int y); ClassOne operator+(const ClassOne& classOne_0) const { ClassOne classOne; classOne.x = (this->x) + classOne_0.x; classOne.y = (this->y) + classOne_0.y; return classOne; } }
operator+()
ClassOne operator+(const ClassOne& classOne_0) const { ClassOne classOne; //REM: Why did this instance select the define `ctor(int, int)` classOne.x = (this->x) + classOne_0.x; classOne.y = (this->y) + classOne_0.y; return classOne; }
int main() { ClassOne c1(4,2); ClassOne c2(2,4); CLassOne c3 = c1 + c2; //REM: `c1 + c2` become temp-var or `rval ref` //REM: if there's no signature for `rval ref` look //REM: for `lval ref to const` ... }
#include <iostream> class ClassOne { private: int x, y; public: ClassOne( int x = 0, int y = 0); // constructor ClassOne operator+(const ClassOne&) const; // operator+() int getX() const { return this->x; } virtual ~ClassOne() { std::cout << "virtual ~ClassOne(V)V\n"; } }; ClassOne::ClassOne( int x, int y ) { std::cout << "ClassOne(I,I)V\n"; this->x = x; this->y = y; } ClassOne ClassOne::operator+ (const ClassOne& classOne_0) const { std::cout << "------------: A what?\n"; ClassOne classOne; //REM: ??? std::cout << "------------\n"; classOne.x = (this->x + classOne_0.x); classOne.y = (this->y + classOne_0.y); return classOne; } int main() { ClassOne c1(4,2); ClassOne c2(2,4); ClassOne c3 = c1 + c2; std::cout << c3.getX() << std::endl; }
C++
class
;
/*explicit*/ ClassOne() : ClassOne(0, 0) { // ctor delegation std::cout << "delegated ClassOne(V)V\n"; } /*explicit*/ ClassOne( int x, int y); // overloaded constructor
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)