C++ Concept Map

Function member definition

If a function member is not defined as inline, then it must be defined outside the class. This done by prefixing the function name with the class name and the scope-resolution operator, :: (colon-colon). This qualifies the name to avoid ambiguity when function names are reused in different classes. This appears to break the rules of scope, because references to variables declared within the scope of the class are allowed in function member definitions. The rules are merely being extended, however, if it is accepted that the definition of the function is "really" contained in the class, but is just placed externally for readability purposes. It also provides a declaration versus implementation view that abstract data typing demands. An exmple of external definition is:

class Ext {
private:
int privateVariable;
public:
void extFun();
...
};

void Ext::extFun() {
privateVariable = 10; // reference to name in the class scope

}


Please mail any corrections and/or suggestions to Roger Hartley at
rth@cs.nmsu.edu

Copyright © 2003 Roger Hartley