473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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

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?
Mar 20 '08 #1
2 1068
Om***********@gmail.com wrote:
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.

--
David Wilkinson
Visual C++ MVP
Mar 20 '08 #2
On Mar 20, 1:16*pm, David Wilkinson <no-re...@effisols.comwrote:
Omar.Khali...@gmail.com wrote:
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.

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

- Show quoted text -
Thanks David!!!
Mar 20 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave | last post by:
In Exceptional C++, the following code snippet appears at the bottom of page 197: template<class T> class Array : private ArrayBase, public Container { typedef Array AIType; public: Array(...
30
by: Joost Ronkes Agerbeek | last post by:
Why is it allowed in C++ to call a static member function of an object through an instance of that object? Is it just convenience? tia, Joost Ronkes Agerbeek
10
by: jim.brown | last post by:
Please refer me to the right place if this is the wrong place to post this question. I'm looking for an example of calling the Eigenvalue routines of JAMA from a C++ program. The documentation...
13
by: RainBow | last post by:
Hi everyone, (Very Sorry, if this is the wrong group in which I am posting this query). Code snippet: //C library typedef int (*PFunc)(int* aArg); void call_c_foo(PFunc aPtrtoFunc) {
2
by: Jan | last post by:
Here's the code with the problem: class Startup { public static string Sym; public static string PrevDate; public static int Highest = new int; // ______________
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
3
by: pauldepstein | last post by:
Sorry in advance if this message sounds imprecise but it's difficult to be precise when you don't really understand what's going on. I have a class called Parameters. The default constructor...
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
1
by: newbie | last post by:
This is a snippet from C++ FAQs, which I have never done--- when I do such a thing, I would declare function used by constructor ( in this example, init() ) as static. But I do understand that it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.