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.