From: horst DOT kraemer AT t-online DOT de (Horst Kraemer) Newsgroups: comp.os.msdos.djgpp Subject: Re: Static member function Date: Wed, 22 Dec 1999 08:33:44 GMT Organization: T-Online Lines: 46 Message-ID: <3860850c.1807805@news.btx.dtag.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news05.btx.dtag.de 945851620 7793 0306239354-0001 991222 08:33:40 X-Complaints-To: abuse AT t-online DOT de X-Sender: 0306239354-0001 AT t-dialin DOT net X-Newsreader: Forte Free Agent 1.11/32.235 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Tue, 21 Dec 1999 22:40:18 -0000, Andrew R. Gillett 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