I have the following:
template <typename X> struct A {
typedef X _X;
};
template <typename Y> struct B { // Y is struct A
typename Y::_X x;
void call_destructor () {
x.~Y::_X(); // This doesn't work
x.Y::~_X(); // This as well
}
};
which doesn't compile, saying that
qualified type does not match destructor name
Using the keyword typename
before the call also does not work. However, the following does compile:
template <typename Y> struct B {
typename Y::_X x;
typedef typename Y::_X __X;
void call_destructor () {
x.~__X(); // This works
}
};
Can someone explain to me why, and is there any way to make do without the typedef
?
You should call the destructor differently using
x.Y::_X::~_X()
The following compile fine for me:
template <typename X> struct A {
typedef X _X;
};
template <typename Y> struct B { // Y is struct A
typename Y::_X x;
void call_destructor () {
x.Y::_X::~_X(); // This as well
}
};
int main(){
B<A<int> > b;
b.call_destructor();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With