|
Boost : |
Subject: [boost] [type_traits] MSVC rejects typename -- why?
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-03-23 19:58:47
Hello all,
The following code compiles on GCC (v3.4.3) but it does not on MSVC
(cl.exe v14):
#include <boost/type_traits.hpp>
template<typename T>
void f(T& x) {
struct s {
T g() {
// GCC needs this typename but MSVC does not -- why??
typename boost::remove_reference<T&>::type i = 0;
return i;
}
};
x = s().g();
}
int main() {
int x;
f(x);
return 0;
}
MSVC does not accept the `typename` inside `s::g` because it says it's
not within a template (but I think it is within a template...). GCC
instead requires that `typename`.
Which compiler is right? (What does the standard say?) How do I
program this code so it works on all compilers?
Thank you very much.
-- Lorenzo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk