mirror of
https://github.com/ioacademy-jikim/android_framwork
synced 2025-06-07 16:06:29 +00:00
5
This commit is contained in:
parent
f25774ff2e
commit
2e9e084a4b
BIN
03_day.pptx
BIN
03_day.pptx
Binary file not shown.
@ -1,7 +1,7 @@
|
|||||||
cc_binary {
|
cc_binary {
|
||||||
name: "my_sp",
|
name: "my_wp",
|
||||||
shared_libs: ["liblog", "libutils"],
|
shared_libs: ["liblog", "libutils"],
|
||||||
srcs: [
|
srcs: [
|
||||||
"sp_1.cpp",
|
"wp_1.cpp",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
119
03_day/sp/wp_1.cpp
Normal file
119
03_day/sp/wp_1.cpp
Normal 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
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user