Forcing a templated object to construct from a pointer
Posted
by SalamiArmi
on Stack Overflow
See other posts from Stack Overflow
or by SalamiArmi
Published on 2010-05-01T16:15:28Z
Indexed on
2010/05/01
16:17 UTC
Read the original article
Hit count: 219
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?
© Stack Overflow or respective owner