Hello.
I have a linking error when using 'static const int';

My code
1.class A
2.{
3. static const int b= 5;
4.};
5. const int A::b;

The code is compile, but i receive a linking error:
multiple definitions of A::b.

if I remove the definition of b outside the class( remove line 5) i receive a linking error :
reference to undefined ....
(the code works in VS without line number 5)

Recommended Answers

All 2 Replies

I'll bet you put line 5 in the header file. Don't. put it in only ONE *.cpp file.

You are absolutly right. 10X.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.