Have a look at the Reset
function below. I know calling constructors and destructors for this
can be dangerous, but I really cannot find what is wrong when used as below. I'm asking this here because I couldn't find any related materials with Google. All I can find is that don't call the constructor within another constructor, and I obviously agree with that. But isn't it safe to call the constructor right after the destructor in a member function?
template<typename T>
class Array{
private:
T* m_p;
Array(const Array&);
Array& operator=(const Array&);
public:
Array(){
m_p=0;
}
Array(int length):
m_p(new T[length]){}
~Array(){
delete[] m_p;
}
void Reset(int length){
this->~Array();
new(this) Array(length);
}
};