why does this code compiles and run on visual studio 2012? is this just a bug or i missing something
namespace SSSS
{
namespace SSS
{
template <class T>
class SS
{
public:
typedef T ValueType;
SS(){std::cout<<T();}
SS(T t) { std::cout<<t;}
};
typedef SS<double> DD;
}
}
int main()
{
SSSS::SSS::DD::SS d;
}
It sounds like your compiler is interpreting SS
as the injected class name; in which case, it is a type, so the declaration is valid.
However, the name lookup rules say that it should instead be interpreted as the constructor, not the class, so your compiler is wrong. Others reject the code: http://ideone.com/7fJ1VM
Valid type names would be the type alias DD
, or an elaborated type specifier using the injected class name, class DD::SS
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.