Calling a static function from a class member method is givinglinking errors

  • Thread starter Thread starter Omar.Khalid79
  • Start date Start date
O

Omar.Khalid79

Hi Guys,

Maybe this is silly thing to ask but I have a static function declared

static void Foo(int a);

defined in Foo.cpp

and a member method which calls Foo

extern void foo(int a);
void A::Test
{
int a = 0;
foo(a);
}

I get linkage errors - 'un-resolved external symbol'. When I change
Foo to non-static, it works. Any ideas?
 
Hi Guys,

Maybe this is silly thing to ask but I have a static function declared

static void Foo(int a);

defined in Foo.cpp

and a member method which calls Foo

extern void foo(int a);
void A::Test
{
int a = 0;
foo(a);
}

I get linkage errors - 'un-resolved external symbol'. When I change
Foo to non-static, it works. Any ideas?

Omar:

Because, in this context, static means "to be used only in this translation
unit". This use of the static keyword is deprecated in C++; use unnamed
namespace instead.

Also, you do not need extern here.
 
Omar:

Because, in this context, static means "to be used only in this translation
unit". This use of the static keyword is deprecated in C++; use unnamed
namespace instead.

Also, you do not need extern here.

--
David Wilkinson
Visual C++ MVP- Hide quoted text -

- Show quoted text -

Thanks David!!!
 
Back
Top