Данный код выполняется без проблем. Куда смотрит милиция?
template <typename T> foo(T t)
{
d.T::~T();
}
//...
foo(5);
заранее спасибо
Здравствуйте, salat, Вы писали:
S>Данный код выполняется без проблем. Куда смотрит милиция?
Данный код не компилируется
S>S>template <typename T> foo(T t)
S>{
S> d.T::~T();
S>}
S>//...
S>foo(5);
S>
S>заранее спасибо
А если серьезно, то
5.2.4/1
The use of a pseudo-destructor-name after a dot . or arrow -> operator represents the destructor for the non-class type named by type-name. The result shall only be used as the operand for the function call operator(), and the result of such a call has type void. The only effect is the evaluation of the postfixexpression before the dot or arrow.
12.4/15
[Note: the notation for explicit call of a destructor can be used for any scalar type name (5.2.4). Allowing this makes it possible to write code without having to know if a destructor exists for a given type. For example,
typedef int I;
I* p;
// ...
p->I::˜I();
—end note]
Если бы это код не компилировался, я бы жег чучело Страуструпа в три раза чаще.