AlexanderVX wrote:
How do I write a constructor mehtod call in this case
/*-----------*/
template<typena me Tclass CObjectPoolImpl
{
public:
void smth(T* pObj)
{
if (pObj)
pObj->T::T(); // an attempt to call a constructor method of class T
new ( (void*) pObj ) T ();
or:
std::allocator< T>().construct ( pObj, T() );
}
};
CObjectPoolImpl <mynamespace::C MyTypeCF;
CMyType mt;
CF.smth(&mt);
/*-----------*/
MS Visual C++ 7.1:
error C2039: 'T' : is not a member of 'mynamespace::C MyType'
There is a reason not to write 'new T' and not to explicitly write
constructor method name (type name). Default constructor method for
CMyType exists.
Note: probably, someonewill tell you that you cannot call a constructor and
that all that you can do is cause the implementation to invoke/call it.
That slogan refers to three facts: (a) constructor calls are not function
calls, (b) the standard, somewhat cryptically, states that constructors
have no names (hence they are not found through name lookup), and (c) the
standard uses the passive voice in talking about constructors being called.
Personally, I find it rather confusing to underscore the difference between
functions calls and constructor calls by taking the linguistic license to
say that we call functions but not taking the license to say that we call
constructors. (You take a linguistic license in either case since the
standard also uses the passive voice when talking about a function being
called: the standard is just not concerned with what programmers do. Also,
a function call according to the standard is just a certain form of
expression: all you do is to write such an expression in your program and
that causes the implementation to invoke the function in the course of
evaluating the expression.)
Best
Kai-Uwe Bux