extern on a static function in C++

Dixon Steel picture Dixon Steel · Oct 27, 2011 · Viewed 18.1k times · Source

I don't know why this is driving me nuts but it is. I have a function defined and forward declared in main.

static void myFunc(int x);

static void myFunc( int x)
{
   //do stuff
}

main()

I want to use myFunc(int x) in another class. So I would think all I have to do is extern static void myFunc(int x) within that classes header and then just call it where I need to in the class definition, but it won't work.

What am I doing wrong?

Thanks

Answer

Alok Save picture Alok Save · Oct 27, 2011

You cannot use extern and static together they are mutually exclusive.

static means Internal Linkage
extern means External Linkage

You need to use only extern if you need External Linkage.

Good Read:
what is external linkage and internal linkage in c++?