2008 January 18th Friday (一月 十八日 金曜日)

typeid

  The typeid operator lets you determine if two objects are the same type. Somewhat like sizeof, it accepts two kinds of arguments:

  * The name of a class

  * An expression that evaluates to an object

  The typeid operator returns a reference to a type_info object, where type_info is a class defined in the typeinfo header file
(formerly typeinfo.h). The type_info class overloads the == and != operators so that you can use these operators to compare types.

A function uses passed data without modifying it:

  If the data object is small, such as a built-in data type or a small structure, pass it by value.

  If the data object is an array, use a pointer because that's your only choice. Make the pointer a pointer to const.

  If the data object is a good-sized structure, use a const pointer or a const reference to increase program efficiency. You save
  the time and space needed to copy a structure or a class design. Make the pointer or reference const.

  If the data object is a class object, use a const reference. The semantics of class design often require using a reference, which
  is the main reason why C++ added this feature. Thus, the standard way to pass class object arguments is by reference.

class string {
public:

  ...

private:
  char *data;

  mutable size_t datalength;
                                  //mutable;can use them
  mutable bool lengthisvalid;     //even if in a const function
};

size_t string::length() const
{
  if (!lengthisvalid) {
    datalength = strlen(data);    // ok
    lengthisvalid = true;         // ok
  }

  return datalength;
}

Nested Quasiquote Forms Evalation Rule

  Quasiquote forms may be nested.  Substitutions are made only for unquoted components appearing at the same nesting
level as the outer most back quote.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值