Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Policy based smart pointer
//Title of this code #include <iostream> template<typename T> class SmartPtr { private: T *p_; const T * getPtr() const { return p_; } T * getPtr() { return p_; } public: SmartPtr(T *p = NULL) : p_(p) { } SmartPtr(const SmartPtr &_ptr) { } const T * operator ->() const { return this->getPtr(); } T * operator ->() { return this->getPtr(); } const T & operator *() const { return this->getPtr(); } T & operator *() { return *this->getPtr(); } }; template<typename T> SmartPtr<T> make_smart(const T &val) { SmartPtr<T> ptr = new T(val); return ptr; } int main() { SmartPtr<int> ptr; std::cout<<*ptr<<'\n'; ptr = make_smart(3); std::cout<<*ptr<<'\n'; *ptr = 4; std::cout<<*ptr<<'\n'; }
run
|
edit
|
history
|
help
0
Switch case
FindKthElementDivideConquer
Cuantos
test111
logcOperator
a simple tuple implementation
Palindromy
Factorial Inv wip
SEGMENTED SIEVE
0/1Knapsack