problems with the C + + static function
Recently read C + + primer in the static chapter, there is such a sentence,
"The declaration of a static member function, in addition to the function declaration in the class body, is preceded by a keyword static and cannot be declared as
A function definition other than const or volatile that appears in the same class body as a non-static member function cannot specify a keyword
Static
Why can't I specify the keyword static outside the class body, so what is the purpose of the design and what is the use?
*
How to say, this is a scope of the problem!
The scope of a member function is a class field, and adding static outside the class body does not represent a static function, it means that the function owns the file domain
And the class domain is smaller than the file domain, forcing the class domain to be extended to the file domain, there will be an error.
The following code:
Class CA {
Public
static void display (void);
};
static void CA::d isplay (void) {//error!
cout << "Hello ca!" << Endl;
}
int main (int argc, char* argv[]) {
CA::d isplay ();
}
Error C2724: ' CA::d isplay ': ' Static ' should not being used on member functions defined at file scope
C + + cannot specify a keyword static outside the class body