Static Member Function Declaration And Definition
This page answers questions like these:
- How to declare a static member function in C++?
- How to define a static member function in C++?
- How to define a static member function in C++?
- What does “warning: cannot declare member function to have static linkage” mean?
- What does “error: cannot declare member function to have static linkage” mean?
- What does “warning: cannot declare member function 'static ...' to have static linkage” mean?
- What does “error: cannot declare member function 'static ...' to have static linkage” mean?
Related Links:
C++ Assignment Operator
Static Assertion / Compile-Time Assertion
warning/error: inline function used but never defined
error: expected primary-expression before ')' token
error: the compiler can assume that the address of '...' will always evaluate to 'true'
How to Declare and Define a Static Member Function in C++?
class CLASS_NAME
{
static int func1(args) // (a) Definition. You must use the static keyword here.
{
...
};
static int func2(args); // (b) Declaration. You must use the static keyword here.
};
int CLASS_NAME::func2(args) // (c) Definition. You must not use the static keyword here.
{
...
};
- Static member functions must use the static keyword inside the class definition (see (a) and (b) above).
- Static member functions must not use the static keyword outside the class definition (see (c) above). If you do, you'll get a compilation warning or error similar to “warning: cannot declare member function 'static ...' to have static linkage”.
- FYI: Static member functions cannot be constant member functions. i.e. they cannot have the keyword const after the declaration or definition.
warning/error: cannot declare member function 'static ...' to have static linkage:
- Static member functions must not use the static keyword outside the class definition (see (c) above).
Related Links:
C++ Assignment Operator
Static Assertion / Compile-Time Assertion
warning/error: inline function used but never defined
error: expected primary-expression before ')' token
error: the compiler can assume that the address of '...' will always evaluate to 'true'
Home > C++ > Static Member Function Declaration And Definition
Tags: warning cannot declare member function to have static linkage, error cannot declare member function to have static linkage, static member function, static class function, C++
Copyright © HelpDoco.com
code-cpp-static-member-function.txt
C++/static-member-function-declaration-and-definition.htm
2