The following code results in the compiler error 'Exception' does not refer to a value
template <typename T>
class A {
public:
virtual ~A() = 0;
class Exception {
};
};
template<typename T>
inline A<T>::~A() {}
template <typename T>
class B : public A<T> {
public:
B() {}
~B() {}
void foo() {
throw B<T>::Exception();
}
};
int main()
{
try {
B<int> instB = B<int>();
instB.foo();
}
catch(B<int>::Exception &e) {
std::cout << "uh oh" << std::endl;
}
}
but, if the type is explicitly specified into the throw, it works. It seems there is an issue in specifying the template type.
throw B<int>::Exception // this works
From Template compilation error: 'X' does not refer to a value this is an indicate that clang is expecting 'Exception' to be a value, not a type.
What is the proper way to thrown the template class Exception?
Aucun commentaire:
Enregistrer un commentaire