diff --git a/03_day.pptx b/03_day.pptx index c23f656..790262a 100644 Binary files a/03_day.pptx and b/03_day.pptx differ diff --git a/03_day/sp/Android.bp b/03_day/sp/Android.bp index 0e8bf69..5250796 100644 --- a/03_day/sp/Android.bp +++ b/03_day/sp/Android.bp @@ -1,7 +1,7 @@ cc_binary { - name: "my_sp", + name: "my_wp", shared_libs: ["liblog", "libutils"], srcs: [ - "sp_1.cpp", + "wp_1.cpp", ], } diff --git a/03_day/sp/wp_1.cpp b/03_day/sp/wp_1.cpp new file mode 100644 index 0000000..84e0156 --- /dev/null +++ b/03_day/sp/wp_1.cpp @@ -0,0 +1,119 @@ +#if 1 +#include +#include +#include + +using namespace android; + +class AAA : public virtual RefBase +{ + int data; + public: + AAA(){ printf("AAA::AAA()\n"); } + ~AAA() { printf("AAA::~AAA()\n"); } + void foo() // void foo( AAA *this ) + { + data = 10; // this->data = 10; => (*0).data = 10; + printf("AAA::foo()\n"); + } +}; + +int main() +{ + //((AAA*)0)->foo(); // AAA::foo(0); + { + wp p1 = new AAA; + { + sp p2 = p1.promote(); + p2->foo(); + } + printf("step 1.\n"); + if( p1.promote() != 0 ) + p1.promote()->foo(); + else + printf("객체는 이미 소멸됨\n"); + } + printf("step 2.\n"); + return 0; +} +#endif + +#if 0 +#include +#include +#include + +using namespace android; + +class AAA : public virtual RefBase +{ + public: + AAA(){ printf("AAA::AAA()\n"); } + ~AAA() { printf("AAA::~AAA()\n"); } + void foo() { printf("AAA::foo()\n"); } +}; + +int main() +{ + { + wp p1 = new AAA; + sp p2 = p1.promote(); + p2->foo(); + } + return 0; +} +#endif +#if 0 +#include +#include +#include + +using namespace android; + +class AAA : public virtual RefBase +{ + public: + AAA(){ printf("AAA::AAA()\n"); } + ~AAA() { printf("AAA::~AAA()\n"); } + void foo() { printf("AAA::foo()\n"); } +}; + +int main() +{ + { + sp p1 = new AAA; + wp p2 = p1; + p1->foo(); + } + return 0; +} +#endif + + +#if 0 +#include +#include +#include + +using namespace android; + +class AAA : public virtual RefBase +{ + public: + AAA(){ printf("AAA::AAA()\n"); } + ~AAA() { printf("AAA::~AAA()\n"); } + void foo() { printf("AAA::foo()\n"); } +}; + +int main() +{ + { + wp pa = new AAA; + pa.promote()->foo(); + } + return 0; +} +#endif + + +