473,387 Members | 1,542 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,387 software developers and data experts.

Linker error with static const field

Hi

I have a class with a public const static variable, and I get a number
of undefined references to it when linking. The code looks like below.
When referencing the variable from other files I use
MaxNode::NO_ARGUMENT. Am I missing something in the definition here,
or would it seem that the problem lies elsewhere?

//MaxNode.hpp:///////////////////
class MaxNode
{
public:
const static double NO_ARGUMENT;
// (etc...)
};

//MaxNode.cpp:////////////////////
#include "MaxNode.hpp"
const static double NO_ARGUMENT = 1123;
// (etc...)
Jul 19 '05 #1
2 2718
Martin Magnusson wrote:
Hi

I have a class with a public const static variable, and I get a number
of undefined references to it when linking. The code looks like below.
When referencing the variable from other files I use
MaxNode::NO_ARGUMENT. Am I missing something in the definition here,
or would it seem that the problem lies elsewhere?

//MaxNode.hpp:///////////////////
class MaxNode
{
public:
const static double NO_ARGUMENT;
// (etc...)
};

//MaxNode.cpp:////////////////////
#include "MaxNode.hpp"
const static double NO_ARGUMENT = 1123;
// (etc...)


const double MaxNode::NO_ARGUMENT = 1123;

Jul 19 '05 #2

"Martin Magnusson" <lo*******@frustratedhousewives.zzn.com> wrote in message news:35*************************@posting.google.co m...
Hi #include "MaxNode.hpp"
const static double NO_ARGUMENT = 1123;

You have just declared a non-class variable called NO_ARGUMENT.
You want:
const double MaxNode::NO_ARGUMENT = 1123;
Jul 19 '05 #3

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

Similar topics

3
by: Jan13 | last post by:
Hi, I'm new to programming in C++ (using VC6) and ran into the following problem: I want to declare and define a class member variable as 'static const', but something seems to go wrong with...
5
by: Minti | last post by:
How do we initialize static const data in C++, I tried class Foo { static const std::string name = "MyName"; }; I don't see any reason as to why this must not work.
3
by: Steven T. Hatton | last post by:
Basically the question is, can I do this?: template <typename T> class Vector3 { public: Vector3(const T& x=0, const T& y=0, const T& z=0) : _v(3) {
5
by: Martin Rennix | last post by:
Eg class Foo { static const float f = 0.0f; // error static const int i = 0; // ok }; What's the reasoning behind this seemingly arbitrary limitation?
3
by: prakash.mirji | last post by:
Hello, I am getting below mention linker error when I tried to link my class test.C I use below command to compile test.C /usr/bin/g++ -g -fpic -fvisibility=default -D_POSIX_SOURCE...
18
by: mati | last post by:
Hi The following code works: #include <vector> class C { private: static const int m_static = 2; public: void f(const std::vector<int>& v)
5
by: sam_cit | last post by:
Hi everyone, I have the following code and it gives a linker error on MS vc++ 6.0. error LNK2001: unresolved external symbol "protected: __thiscall Singleton::Singleton(void)"...
5
by: Miguel Guedes | last post by:
Hello, Why can't non-integral static const data members be initialized within a class? I know how to initialize the members but I don't understand the underlying reason to this rule. Would...
1
by: Deepath G | last post by:
This is deepath.. I am getting some linker error when i am trying to connect Websphere MQ using Borland C++ Builder 2006 using imqi.hpp on windows. Error Message ----------------------- ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.