Co-authored-by: sigonasr2 <sigonasr2@gmail.com>master
parent
dba7479803
commit
7276e3cff3
Binary file not shown.
@ -1,37 +1,40 @@ |
|||||||
#define OLC_PGE_APPLICATION |
#include <memory> |
||||||
#include "pixelGameEngine.h" |
#include <stdio.h> |
||||||
#include <unordered_map> |
|
||||||
#include "Block.h" |
|
||||||
|
|
||||||
class Example : public olc::PixelGameEngine |
class C2{ |
||||||
{ |
|
||||||
public: |
public: |
||||||
Example() |
int data=4; |
||||||
{ |
~C2(){ |
||||||
sAppName = "Example"; |
printf("C2 destroyed\n"); |
||||||
} |
} |
||||||
|
}; |
||||||
|
|
||||||
|
class C1{ |
||||||
public: |
public: |
||||||
std::unordered_map<int,Block> Blocks; |
~C1(){ |
||||||
bool OnUserCreate() override |
printf("C1 destroyed\n"); |
||||||
{ |
|
||||||
// Called once at the start, so create things here
|
|
||||||
Blocks[126]=Block(25,10,255,255,255); |
|
||||||
return true; |
|
||||||
} |
} |
||||||
|
void PrintData(std::weak_ptr<C2>ptr) { |
||||||
bool OnUserUpdate(float fElapsedTime) override |
printf("Data is %d\n",ptr.lock()->data); |
||||||
{ |
|
||||||
return true; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
|
|
||||||
|
|
||||||
int main() |
int main(){ |
||||||
{ |
|
||||||
Example demo; |
std::shared_ptr<C1> ptrA{std::make_shared<C1>()}; |
||||||
if (demo.Construct(256, 240, 4, 4)) |
|
||||||
demo.Start(); |
std::weak_ptr<C1>ptrA_2=ptrA; |
||||||
|
if (!ptrA_2.expired()) { |
||||||
|
printf("Count:%ld",ptrA.use_count()); |
||||||
|
std::shared_ptr<C1> ptrA_3{ptrA}; |
||||||
|
printf("Inside if statement.\n"); |
||||||
|
std::shared_ptr<C2> ptrB{std::make_shared<C2>()}; |
||||||
|
ptrA_2.lock()->PrintData(ptrB); |
||||||
|
printf("Count:%ld",ptrA.use_count()); |
||||||
|
} |
||||||
|
printf("Count:%ld",ptrA.use_count()); |
||||||
|
printf("Outside if statement.\n"); |
||||||
|
|
||||||
return 0; |
return -1; |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue