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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.