###Missing Featres
Missing Featres
Code Review
###Code Review YouYou can initialize POD data on creation with new.
###Missing Featres
###Code Review You can initialize POD data on creation with new.
Missing Featres
Code Review
You can initialize POD data on creation with new.
In the assignment operator you use the "Copy and Swap Idiom". But you use an atypical version. It is more common to use a pass by value version (you silently get an implicit copy). This version (apparently) has better opportunities for optimization. In depth description: What is the copy-and-swap idiom? What is the copy-and-swap idiom?
In the assignment operator you use the "Copy and Swap Idiom". But you use an atypical version. It is more common to use a pass by value version (you silently get an implicit copy). This version (apparently) has better opportunities for optimization. In depth description: What is the copy-and-swap idiom?
In the assignment operator you use the "Copy and Swap Idiom". But you use an atypical version. It is more common to use a pass by value version (you silently get an implicit copy). This version (apparently) has better opportunities for optimization. In depth description: What is the copy-and-swap idiom?
- release()
There is no way to give up ownership. - reset()
You have to work around using Constructor and assignment. But this is complicated by not working with temporaries (no move semantics). - Move Semantics
Both constructor and assignment versions would be nice. - No way to break cycles (Weak Pointer).
- swap()
- No relational operators defined.
So you can not put it in a map/set.
template <class T>
SharedPointer<T>::SharedPointer(void) // don't use void :-( as a parameter.
: ptr(new T())
, counter(new int(1))
{}
- release()
There is no way to give up ownership. - reset()
You have to work around using Constructor and assignment. But this is complicated by not working with temporaries (no move semantics). - Move Semantics
Both constructor and assignment versions would be nice. - No way to break cycles (Weak Pointer).
- swap()
template <class T>
SharedPointer<T>::SharedPointer(void)
: ptr(new T())
, counter(new int(1))
{}
- release()
There is no way to give up ownership. - reset()
You have to work around using Constructor and assignment. But this is complicated by not working with temporaries (no move semantics). - Move Semantics
Both constructor and assignment versions would be nice. - No way to break cycles (Weak Pointer).
- swap()
- No relational operators defined.
So you can not put it in a map/set.
template <class T>
SharedPointer<T>::SharedPointer() // don't use void :-( as a parameter.
: ptr(new T())
, counter(new int(1))
{}