954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

link ereror using static const int

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)

kerenLinux
Newbie Poster
5 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

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

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

You are absolutly right. 10X.

kerenLinux
Newbie Poster
5 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You