Another problem with decltype

Posted by There is nothing we can do on Stack Overflow See other posts from Stack Overflow or by There is nothing we can do
Published on 2011-02-22T07:17:56Z Indexed on 2011/02/22 7:24 UTC
Read the original article Hit count: 137

Filed under:
|
|
template<class IntT, IntT low = IntT(), IntT high = IntT()>
struct X 
{
    static_assert(std::is_same<decltype(low),decltype(high)>::value,"Different types not allowed");//this should give error if types are different
    decltype(low) a;
    decltype(high) b;
    X():a(decltype(a)()),b(decltype(b)())//WHY THIS DOES NOT COMPILE?
    {
        cout << typeid(a).name() << '\n';
        cout << typeid(b).name() << '\n';
    }
};

int _tmain(int argc, _TCHAR* argv[])
{


    X<char,1,'a'> x;//this according to static_assert shouldn't compile but it does

    return 0;
}

Using VS2010.
Please see 3 comments in code above.

© Stack Overflow or respective owner

Related posts about c++

Related posts about decltype