Category : smart-pointers

which one of singleton implementation is better and what are advantages and disadvantages? //first class singleton_SharedPtr{ public: singleton_SharedPtr(const singleton_SharedPtr&) = delete; singleton_SharedPtr& operator=(const singleton_SharedPtr&) = delete; ~singleton_SharedPtr(){} //is it normal to return weak_ptr instead of share_ptr in the getInstance method???? static std::shared_ptr<int> getInstance(){ std::cout<<"referenced before if condfition, use_count : "<<instance.use_count()<<std::endl; if(instance==nullptr){ instance=std::make_shared<int>(); } std::cout<<"referenced after ..

Read more

I am currently experimenting with the ESP32-CAM, which is a microcontroller with integrated camera that you can program through the Arduino IDE (with C++11). For capturing images with the cam, there is a library called ‘esp32cam’, which contains the function esp32cam::capture(). This function apparently returns a variable with the type std::unique_ptr<esp32cam::Frame>. There is also an ..

Read more

In real applications I should stick to the standard library facilities, for practice and understanding how those facilities work I should try to implement my own. Here I’ve implemented a simulation of the smart pointer unique_ptr: #include<iostream> #include <memory> template <typename T> class DefDel { public: template <typename U> void operator()(U* p)const { std::cout << ..

Read more