C++ Basic Features List

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值