diff --git a/.drone.yml b/.drone.yml index 6b04d72..70581d4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,8 +1,12 @@ kind: pipeline name: default steps: -- name: test - image: gcc:latest - commands: - - gcc hello.c -o hello - - ./hello \ No newline at end of file + - name: test + image: gcc:latest + commands: + - echo "*****hello*****" + - gcc hello.cpp -o hello && ./hello + + - cd class || exit + - echo "*****construct*****" + - gcc construct.cpp -o construct && ./construct diff --git a/class/construct.cpp b/class/construct.cpp new file mode 100644 index 0000000..8e52695 --- /dev/null +++ b/class/construct.cpp @@ -0,0 +1,81 @@ +#include + +using namespace std; + +class A { + public: + A(int) { + cout << "A constructed at " << this << " with " << i << " at " << &i << endl; + this->i = i; + } + A() { + cout << "A constructed at " << this << endl; + this->i = 0; + } + A& operator=(const A& a) { + cout << "A assign constructed at " << this << " with a at " << &a << endl; + return *this; + } + ~A() { cout << "A destructed at " << this << " with val " << i << endl; } + + private: + int i; +}; + +class Uniq { + public: + Uniq() {} + void copy(Uniq& from) { *this = from; } + void setVal(int val) { this->val = val; } + int getVal() { return val; } + + private: + Uniq(const Uniq&); + Uniq& operator=(const Uniq& from) { + cout << "Uniq hidden copy assign func called" << endl; + val = from.val; + return *this; + } + int val; +}; + +class Empty { + public: + Empty() { cout << "Empty constructed at " << this << endl; } + ~Empty() { cout << "Empty destructed at " << this << endl; }; +}; + +class B { + private: + int i; + A a; + + public: + B(A a) + : a(a) { + cout << "B constructed at " << this << " with A at " << &a << endl; + } + ~B() { cout << "B destructed at " << this << endl; } +}; + +int main() { + cout << "construct via new" << endl; + new Empty; + cout << "construct in sizeof()" << endl; + cout << __LINE__ << ": " << sizeof(*(new Empty)) << endl; + A a; + A aa = a; + a = (const A&)aa; + B b(a); + B bb = b; + Uniq u; + u.setVal(15); + cout << __LINE__ << ": " << u.getVal() << endl; + // Uniq u1(u); + // Uniq u2; + // u2 = u; + Uniq* u2 = new Uniq; + cout << __LINE__ << ": " << u2->getVal() << endl; + u2->copy(u); + cout << __LINE__ << ": " << u2->getVal() << endl; +} \ No newline at end of file