May 2003
Intermediate to advanced
808 pages
32h 24m
English
A function declaration tells the compiler about a function name and how to call the function. The actual body of the function can be defined separately (described later in this chapter). A function declaration has the following parts:
typename(parameters)cv-qualifiersexcept-spec;
The parameters,
cv-qualifiers, and
except-spec are optional. The
type is required, except for constructors,
destructors, and type conversion operators. The
name is the function name. (Each of these
parts is described later in this chapter.) Example 5-1 shows a variety of
function declarations.
// Function named "add", which returns type int, and takes two parameters, each // of type int. The names a and b are optional.int add(int a, int b);// Function named "print", which takes a const string reference, and does not // return anything. The function is expanded inline.inline void print(const std::string& str){ std::cout << str; } // Function named "test", which takes two floating-point arguments and returns an // enumeration. This function does not throw any exceptions. enum fptest { less=-1, equal, greater };fptest test(double, double) throw( );class demo { public: // Member function named "value", which returns type int, takes no arguments, // and is const, which means it can be called for a const object.int value( ) const;// Function named "~demo", that is, a destructor, that is virtual. Constructors // and destructors do not have return ...
Read now
Unlock full access