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 "pixelGameEngine.h" |
||||
#include <unordered_map> |
||||
#include "Block.h" |
||||
#include <memory> |
||||
#include <stdio.h> |
||||
|
||||
class Example : public olc::PixelGameEngine |
||||
{ |
||||
public: |
||||
Example() |
||||
{ |
||||
sAppName = "Example"; |
||||
class C2{ |
||||
public: |
||||
int data=4; |
||||
~C2(){ |
||||
printf("C2 destroyed\n"); |
||||
} |
||||
}; |
||||
|
||||
public: |
||||
std::unordered_map<int,Block> Blocks; |
||||
bool OnUserCreate() override |
||||
{ |
||||
// Called once at the start, so create things here
|
||||
Blocks[126]=Block(25,10,255,255,255); |
||||
return true; |
||||
class C1{ |
||||
public: |
||||
~C1(){ |
||||
printf("C1 destroyed\n"); |
||||
} |
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override |
||||
{ |
||||
return true; |
||||
void PrintData(std::weak_ptr<C2>ptr) { |
||||
printf("Data is %d\n",ptr.lock()->data); |
||||
} |
||||
}; |
||||
|
||||
|
||||
int main() |
||||
{ |
||||
Example demo; |
||||
if (demo.Construct(256, 240, 4, 4)) |
||||
demo.Start(); |
||||
int main(){ |
||||
|
||||
std::shared_ptr<C1> ptrA{std::make_shared<C1>()}; |
||||
|
||||
return 0; |
||||
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 -1; |
||||
} |
||||
|
Loading…
Reference in new issue