473,503 Members | 5,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

static data-member treated as extern

The following short program compiles fine but fails to link (both on
Borland C++ and GNU g++). In particular, g++ gives this link error:
"undefined reference to `VarArrar::funct'".

It seems as if the static data-member (of type Funct) is regarded as
an external, hence unresolvable by 'ld'. If so, why is a static member
considered an extern, and what is the remedy?
Jul 22 '05 #1
2 2137
Scott J. McCaughrin wrote:
The following short program
What short program?
compiles fine but fails to link (both on
Borland C++ and GNU g++). In particular, g++ gives this link error:
"undefined reference to `VarArrar::funct'".

It seems as if the static data-member (of type Funct) is regarded as
an external, hence unresolvable by 'ld'. If so, why is a static member
considered an extern, and what is the remedy?


Why? Because it is. The remedy is to define it.

V
Jul 22 '05 #2

"Scott J. McCaughrin" <sj******@bluestem.prairienet.org> wrote in message
news:cm**********@wildfire-pl.prairienet.org...
The following short program compiles fine but fails to link (both on
Borland C++ and GNU g++). In particular, g++ gives this link error:
"undefined reference to `VarArrar::funct'".

It seems as if the static data-member (of type Funct) is regarded as
an external, hence unresolvable by 'ld'. If so, why is a static member
considered an extern, and what is the remedy?


If it were not then every source file in which you included the class
definition would get a separate definition of the static data member,
resulting in multiple definition errors.

The remedy is the same as with globals, define the static data member in one
source file

Funct SomeClass::some_member = something;

john
Jul 22 '05 #3

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

Similar topics

18
5729
by: Erik Arner | last post by:
Hi, I really need some help here. After upgrading to g++ 3.4 I have run into all sorts of troubles that I'm sure depends on my lack of proper understanding of C++. I would now like to get it right...
3
2088
by: Jay | last post by:
Why are there static methods in C#. In C++ static was applied to data only (I believe) and it meant that the static piece of data was not a part of the object but only a part of the class (one...
4
2025
by: Joe Fallon | last post by:
In another post Kevin Spencer stated: "one should be careful of using static fields, properties, and methods, by understanding what the implications of such are (e.g. locking static variables when...
6
1747
by: Richard | last post by:
Hi, I write mostly winform app and often create a Business Class Library for my bus logic. When doing this I often set the method to static so I don't need to instantiate the class. Can I do...
15
2143
by: dn | last post by:
I'm starting an n-tier application with an ASP.NET 2.0 presentation layer, a business layer, a data access layer, and a SQL Server 2005 database, and I have a question. In the business and data...
9
2150
by: Pohihihi | last post by:
What could be the possible reasons (technical/non technical) of not using lots of static functions or variables in a program keeping in mind that Framework by itself has tons of static functions and...
7
2381
by: Jon Vaughan | last post by:
I have a piece of code that I want to run on a Pocket Pc, I have written a data class that will store the small amount of data that is required for the program. As this class will be used via a few...
10
7837
by: sunil | last post by:
Hello, I am new to c# . I have some basic programming doubts. Please help me in clarifying these doubts. I want to initialize a static and readonly field with a value returned by a static...
2
1554
by: mark4asp | last post by:
Q: Initialising and updating a class with only static members & database dependency I have a class with the following members: public static List<ACISACIS_List; static AssetClass() { //...
4
4502
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
0
7193
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
7067
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
7264
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,...
1
6975
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
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4992
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...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.