Mail Archives: djgpp/1999/12/22/16:38:54
On Tue, 21 Dec 1999 22:40:18 -0000, Andrew R. Gillett
<arganoid AT fatal-design DOT com> wrote:
> static dog_class* dog_class::breed (dog_class* dog1, dog_class* dog2)
>
> entity.cpp:30: cannot declare member function `dog_class::breed(dog_class
> *, dog_class *)' to have static linkage
>
> This is the first time I have used static member functions in a class. I
> don't understand why this doesn't work. Anyway, that's not the
> declaration, it's the definition. It didn't complain on the declaration.
This is the correct way to do it
class dog_class
{
public:
// declaration
static dog_class* breed (dog_class*, dog_class*);
};
// definition. No 'static' here.
dog_class* dog_class::breed (dog_class* dog1, dog_class* dog2)
{
code
}
Unfortuately the word 'static' is "overloaded" in C++ and has distinct
meanings according to the context.
'static' inside a class definition declaring a 'static member
function' has nothing to do with the 'storage class static' used for
normal function definitions/declarations
static void f() {}
defines a normal function with internal linkage, i.e. a function which
is only visible in the translation unit where it is defined. A static
member function of a class cannot be defined to have internal linkage.
Therefore the static inside the class definition and the 'static' in
the member function's definition are conflicting - although it's the
same word...
Regards
Horst
- Raw text -