Relaxing “Declare Before Use” Within Classes

Members of a class are declared in the class declaration. In the implementation, the order of declarations in the class does not affect visibility, so a member function declared first in the class can call on a function declared fifth. In effect, every member in the class declaration is visible to every member function implementation.

This does not hold true within the class declaration. The following would be invalid because anOperator has not been declared before it is used for a formal argument in Accumulate():

void Accumulate
(
    anOperator theOperator,
    float theOperand = 0
);
enum anOperator
   {add,subtract,multiply,divide,query,reset} ;

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.