1. typename
Here, in excruciating detail, are the rules for the use of typename. Unfortunately, due to something which is hopefully not-contagious apparently affecting the standards committee, they are pretty complicated.
- typename is prohibited in each of the following scenarios:
- Outside of a template definition. (Be aware: an explicit template specialization (more commonly called atotal specialization, to contrast with partial specializations) is not itself a template, because there are no missing template parameters! Thustypename is always prohibited in a total specialization.)
- Before an unqualified type, like int or my_thingy_t.
- When naming a base class. For example, template <class C> class my_class : C::some_base_type { ... }; maynot have atypename beforeC::some_base_type.
- In a constructor initialization list.
- typename is mandatory before a qualified, dependent name which refers to a type (unless that name is naming a base class, or in an initialization list).
- typename is optional in other scenarios. (In other words, it is optional before a qualified butnon-dependent name used within a template, except again when naming a base class or in an initialization list.)
http://pages.cs.wisc.edu/~driscoll/typename.html#real_reason
2. Nested class
A nested class is declared within the scope of another class. The name of a nested class is local to its enclosing class. Unless you use explicit pointers, references, or object names, declarations in a nested class can only use visible constructs, including type names, static members, and enumerators from the enclosing class and global variables.
Member functions of a nested class follow regular access rules and have no special access privileges to members of their enclosing classes. Member functions of the enclosing class have no special access to members of a nested class.
3. Friend class
In VS2010, when we declare a class (with template type) as friend class, it's not allowed to append template types,
Here is an example, in VS 2003, the below code is fine, but in VS 2010, the red text have to be deleted.
template<class T_key, class T_value>
class EWHashMap
{
public:
EWHashMap(void);
~EWHashMap(void);
class EWHashMapLiterator
{
friend class EWHashMap<class T_key, class T_value>;
};
private:
int myLength;
friend EWHashMapLiterator;
};
4. Conversion operators
A conversion operator can be thought of as user-defined typecasting operator, it converts its object to a different type in contexts that require that specific type.
Ref: http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=24