1
0
mirror of https://github.com/ioacademy-jikim/android_framwork synced 2025-06-07 16:06:29 +00:00
This commit is contained in:
ioacademy-jikim 2018-06-14 13:52:04 +09:00
parent f25774ff2e
commit 2e9e084a4b
3 changed files with 121 additions and 2 deletions

Binary file not shown.

View File

@ -1,7 +1,7 @@
cc_binary {
name: "my_sp",
name: "my_wp",
shared_libs: ["liblog", "libutils"],
srcs: [
"sp_1.cpp",
"wp_1.cpp",
],
}

119
03_day/sp/wp_1.cpp Normal file
View File

@ -0,0 +1,119 @@
#if 1
#include <stdio.h>
#include <utils/RefBase.h>
#include <utils/StrongPointer.h>
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<AAA> p1 = new AAA;
{
sp<AAA> 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 <stdio.h>
#include <utils/RefBase.h>
#include <utils/StrongPointer.h>
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<AAA> p1 = new AAA;
sp<AAA> p2 = p1.promote();
p2->foo();
}
return 0;
}
#endif
#if 0
#include <stdio.h>
#include <utils/RefBase.h>
#include <utils/StrongPointer.h>
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<AAA> p1 = new AAA;
wp<AAA> p2 = p1;
p1->foo();
}
return 0;
}
#endif
#if 0
#include <stdio.h>
#include <utils/RefBase.h>
#include <utils/StrongPointer.h>
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<AAA> pa = new AAA;
pa.promote()->foo();
}
return 0;
}
#endif