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

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?
 
D

David Wilkinson

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.
 
O

Omar.Khalid79

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!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top