R
Robert Allan Schwartz
Why do I get a syntax error below?
I don't see why volatile works but unsigned does not work.
I'm not looking for an answer of the form, "Because the Standard says
so", or "Because the C++ grammer says so"; I'm looking for an
explanation of *why* the Standard and/or the grammar say so.
Thanks,
Robert Schwartz
#include <iostream>
template <typename T>
class is_volatile/*<T>*/
{ public: static const bool value = false; };
template <typename T>
class is_volatile<volatile T>
{ public: static const bool value = true; };
template <typename T>
void test1(void)
{
std::cout << is_volatile<T>::value << std::endl;
}
template <typename T>
class is_unsigned/*<T>*/
{ public: static const bool value = false; };
template <typename T>
class is_unsigned<unsigned T> // "syntax error before '>' token" on
this line.
{ public: static const bool value = true; };
template <typename T>
void test2(void)
{
std::cout << is_unsigned<T>::value << std::endl;
}
int main(void)
{
test1<volatile int>();
test2<unsigned int>();
return 0;
}
I don't see why volatile works but unsigned does not work.
I'm not looking for an answer of the form, "Because the Standard says
so", or "Because the C++ grammer says so"; I'm looking for an
explanation of *why* the Standard and/or the grammar say so.
Thanks,
Robert Schwartz
#include <iostream>
template <typename T>
class is_volatile/*<T>*/
{ public: static const bool value = false; };
template <typename T>
class is_volatile<volatile T>
{ public: static const bool value = true; };
template <typename T>
void test1(void)
{
std::cout << is_volatile<T>::value << std::endl;
}
template <typename T>
class is_unsigned/*<T>*/
{ public: static const bool value = false; };
template <typename T>
class is_unsigned<unsigned T> // "syntax error before '>' token" on
this line.
{ public: static const bool value = true; };
template <typename T>
void test2(void)
{
std::cout << is_unsigned<T>::value << std::endl;
}
int main(void)
{
test1<volatile int>();
test2<unsigned int>();
return 0;
}