error LNK2005 ...killin me!

My instructor gave me an assignment that involves modifying a class that HE has already prewritten. He gave us the Header, Implementation, and a test app to use that was supposed to be working when we got it. Unfortunately me and one of my friends have both been getting the same error, error LNK2005. I overheard another kid talking about working on it so idk how he got it working but I have yet to find a fix.

Below is the portion of the header that I believe contains the problem, because the error says
"error LNK2005: "public: static unsigned int const bag::CAPACITY" (?CAPACITY@bag@@2IB) already defined in bag_demo.obj"

1
2
3
4
5
6
7
8
9
10
11
#ifndef BAG_H
#define BAG_H
#include <cstdlib>  // Provides size_t

    class bag
    { 
    public:
        // TYPEDEFS and MEMBER CONSTANTS
        typedef int value_type;
        typedef std::size_t size_type;
        static const size_type CAPACITY =30;


Here is the implementation of the constant CAPACITY:
1
2
3
4
5
6
#include <algorithm> // Provides copy function
#include <cassert>   // Provides assert function
#include "bag.h"
using namespace std;

const bag::size_type bag::CAPACITY;



If you have any idea please let me know, if you think it might be something else I can post the full header, etc. I tried researching this error but what I found didnt seem to help. When my friend emailed the professor the prof just told him to remove the static from it..which just throws more errors.
Do one of the following:

1) remove the = 30 from the header and put it on line 6 of the cpp file

or

2) remove line 6 from the cpp file


I would do #2 as it's less likely to have other side effects.
thanks Disch, I removed line 6 from the cpp and it seems to be working fine. I didn't know it could run without that line!
Topic archived. No new replies allowed.