2008 January 18th Friday (一月 十八日 金曜日)
2008-06-02 11:17
387 查看
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.
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.
相关文章推荐
- 2008 January 4th Friday (一月 四日 金曜日)
- 2008 April 18th Friday (四月 十八日 金曜日)
- 2008 January 25th Friday (一月 二十五日 金曜日)
- 2008 July 18th Friday (七月 十八日 金曜日)
- January 9th Friday 2009 (一月 九日 金曜日)
- January 23th Friday 2009 (一月 二十三日 金曜日)
- May 18th Friday (五月 十八日 金曜日)
- 2008 January 17th Thursday (一月 十七日 木曜日)
- 2008 August 8th Friday (八月 八日 金曜日)
- 2008 August 22th Friday (八月 二十二日 金曜日)
- 2008 September 19th Friday (九月 十九日 金曜日)
- Februray 9th Friday (一月 九日 金曜日)
- 2008 January 7th Monday (一月 七日 月曜日)
- 2008 January 22th Tuesday (一月 二十二日 火曜日)
- 2008 February 18th Monday (二月 十八日 月曜日)
- 2008 March 21th Friday (三月 二十一日 金曜日)
- 2008 July 4th Friday (七月 四日 金曜日)
- 2008 September 5th Friday (九月 五日 金曜日)
- 2008 November 21th Friday (十一月 二十一日 金曜日)
- 2008 January 8th Tuesday (一月 八日 火曜日)