Forcing a templated object to construct from a pointer
- by SalamiArmi
I have a fictional class:
template<typename T> class demonstration
{
public:
demonstration(){}
...
T *m_data;
}
At some point in the program's execution, I want to set m_data to a big block of allocated memory and construct an object T there.
At the moment, I've been using this code:
void construct()
{
*m_data = T();
}
Which I've now realised is probably not the best idea... wont work under certain cirumstances, if T has a private assignment operator for example.
Is there a normal/better way to do what I'm attempting here?