Recently I read a piece of code like this:
template <unsigned long size>
class FooBase
{
bool m_bValid;
char m_data[size];
};
template <class T>
class Foo : public FooBase<sizeof(T)>
{
// it's constructor
Foo(){};
Foo(T const & t) {construct(t); m_bValid = (true);}
T const * const GetT() const { return reinterpret_cast<T const * const>(m_data); }
T * const GetT() { return reinterpret_cast<T * const>(m_data);}
// could anyone help me understand this line??
void construct(T const & t) {new (GetT()) T(t);}
};
I have sliced the code to make sure it's not that complicated, the main question is about the construct(T const & t)
function.
What does new (GetT()) T(t);
exactly means?
btw, which version of GetT()
is called?