class working with int or string

We've been working on a class (bag) that holds values in no particular order. This is the original definition, where the bag holds ints:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class bag
    { 
    public:
        // TYPEDEFS and MEMBER CONSTANTS
        typedef int value_type;
        typedef std::size_t size_type;
        // CONSTRUCTOR
        bag( ) { used = 0; } 
        // MODIFICATION MEMBER FUNCTIONS
        size_type erase(const value_type& target);
        bool erase_one(const value_type& target);
        void insert(const value_type& entry);
        void operator +=(const bag& addend);
        // CONSTANT MEMBER FUNCTIONS
        size_type size( ) const { return used; }
	size_type capacity() const {return CAPACITY;}
        size_type count(const value_type& target) const;
    private:
	static const size_type CAPACITY=30;
        value_type data[CAPACITY];  // The array to store items
        size_type used;             // How much of array is used
    };


I won't post all the implementation specifics(unless I need to), I'll just say that everything works the way it is supposed to.
The second part of the assignment is to change the type of data the bag holds from ints to strings. This should be easy(I thought), since I used:
 
typedef int value_type;

and everywhere in the class, I used value_type instead of int. I would think that all I have to do is change that line to:
 
typedef string value_type;

and everywhere in the class, string would replace int as the value_type.
when I change it, I get:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class bag
 { 
    public:
        // TYPEDEFS and MEMBER CONSTANTS
        typedef string value_type;
        typedef std::size_t size_type;
        // CONSTRUCTOR
        bag( ) { used = 0; } 
        // MODIFICATION MEMBER FUNCTIONS
        size_type erase(const value_type& target);
        bool erase_one(const value_type& target);
        void insert(const value_type& entry);
        void operator +=(const bag& addend);
        // CONSTANT MEMBER FUNCTIONS
        size_type size( ) const { return used; }
	size_type capacity() const {return CAPACITY;}
        size_type count(const value_type& target) const;
    private:
		static const size_type CAPACITY=30;
        value_type data[CAPACITY];  // The array to store items
        size_type used;             // How much of array is used
 };

When I compile, I get tons of errors that seem to me to be all related. Line 68 in these errors corresponds to line 5 above

bag1.h(68) : error C2146: syntax error : missing ';' before identifier 'value_type'
bag1.h(68) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
bag1.h(68) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
bag1.h(74) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
bag1.h(74) : error C2143: syntax error : missing ',' before '&'
bag1.h(75) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
bag1.h(75) : error C2143: syntax error : missing ',' before '&'
bag1.h(76) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
bag1.h(76) : error C2143: syntax error : missing ',' before '&'
bag1.h(81) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
bag1.h(81) : error C2143: syntax error : missing ',' before '&'
bag1.h(84) : error C2146: syntax error : missing ';' before identifier 'data'
bag1.h(84) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
bag1.h(84) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

I have #include <string> in both the header and implementation file. Is there something specific about the string class that prevents it from being used in this way? or have I made a silly mistake?
I have #include <string> in both the header and implementation file. Is there something specific about the string class that prevents it from being used in this way? or have I made a silly mistake?


Silly Mistake.

Hint:
Compare the way you have wriiten these two line. Something is missing from the first one.
1
2
        typedef string value_type;
        typedef std::size_t size_type;
DOH!!!!!!
I am so used to using string without specifying the namespace.
Thanks
Topic archived. No new replies allowed.