On Saturday, 2 May 2015 19:28:26 UTC+3, Stefan Ram wrote:
> You can declare a variable thus
>
> int i;
>
> , although »int« is a type name, the compiler did not accept
>
> typename int i;
>
> , but it did accept
>
> typename ::std::string s;
>
> , however, it did not accept
>
> class ::std::string s;
>
> because ::std::string is typedef, it is not a class, but it
> would accept
>
> class a_class a;
>
> if »a_class« is a proper class.
It is well-formed also when 'a_class' is 'struct', but several
compilers will warn about it.
> Do you know a type from the standard library that actually
> /is/ a class? (not a template or a typedef)
Lets be curious and check what typedef the 'std::string' is? It is
required to be (in 'std' namespace):
typedef basic_string<char> string;
So lets see further what is the mysterious 'basic_string'? It is
required to be such a thing:
template < class charT
, class traits = char_traits<charT>
, class Alloc = allocator<charT>
>
class basic_string;
Wow, a 'class' template. So we may type:
class std::basic_string<char> s1;
Since further research about 'std::char_traits' and 'std::allocator'
shows that these are class templates as well we may type:
class ::std::basic_string<char, class ::std::char_traits<char>,
class ::std::allocator<char> > s2;
and that declaration must be equal with:
std::string s2;
However ... don't you have something more basic to teach your
students about software development? The allocators and character
traits are rather advanced topic. One may work for years in C++
shop and not care about those.