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
typedefint value_type;
typedef std::size_t size_type;
staticconst 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"
usingnamespace 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.