Wednesday, June 13, 2007

3.1 The binding of a Data Member

The body of an inline function is not evaluated until after the entire class declaration is seen.

typedef int length;
class Point3d
{
public:
mumble (length val) { _val = val;} // length resolves to global, _val resolves to Point3d::_val
private:
typedef float length;
length _val;
}
When the subsequent declaration of the nested typedef of length is encountered, the Standard requires that the earlier bindings be flagged as illegal. This aspect of the language still requires the general defensive programming style of always placing nested typedef declarations at the beginning of the class.

No comments: