Linker error with static const field

M

Martin Magnusson

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...)
 
R

red floyd

Martin said:
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;
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top