Compiler error c2724

bjoarn
bjoarn used Ask the Experts™
on
i want to declare static member functions in a class definition inside a header-file and implement them in a .cpp file.
All i get is this error, which obviously says, that it is not allowed.
Do you have to implement the static members in the header-file (where the class definition resides)? i hope there is another way, because that would make the header file useless for me, as i only want definitions in them, not code!
What does this external linkage do and is it common to use it?

//////////////////////////////

Compiler Error C2724
'identifier' : 'static' should not be used on member functions defined at file scope

A static member function was defined at file scope. Static member functions should be declared with external linkage.

This is a warning when Microsoft extensions are used (/Ze) and is an error when Microsoft extensions are disabled (/Za).

The following is an example of this error:

class C
{
   static void func();
};

static void C::func(){};    // error
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You need to use static keyword only in h-file:

// h-file
class C
{
  static void func();
};

// cpp file

void C::func()
{
    // implementation
}

Author

Commented:
Thanks very much :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial