Struggling with Class Inheritance.

I am having some serious issues with class inheritance. I am trying to make a MoneyBag class inherit from a class called bag. This will not work. I get an error complaining: error: expected class-name before '{' token. And yes I have googleing it and tried several of the various solutions offered with no avail.

The MoneyBag is pretty simple right now as I wanted to get it connected to bag before I tried to do anything with it.

//MoneyBag.h//

#ifndef MONEYBAG_H
#define MONEYBAG_H

#include <bag.h>


class MoneyBag : public bag{ ////<<------ Error appears on this line.

public:
MoneyBag();
virtual ~MoneyBag();
protected:
private:
};

#endif // MONEYBAG_H

The bag class header file that is the parent
//bag.h//

#ifndef MAIN_SAVITCH_BAG1_H
#define MAIN_SAVITCH_BAG1_H
#include <cstdlib> // Provides size_t
#include <iostream>
#include <ostream>

using namespace std;

namespace main_savitch_3
{
class bag
{
public:
// TYPEDEFS and MEMBER CONSTANTS
typedef int value_type;
typedef std::size_t size_type;
static const size_type CAPACITY = 30;
// 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 count(const value_type& target) const;

value_type getItem(size_type i) const;
friend ostream& operator<<(ostream& out, const bag& aBag);

private:
value_type data[CAPACITY]; // The array to store items
size_type used; // How much of array is used
};

// NONMEMBER FUNCTIONS for the bag class
bag operator +(const bag& b1, const bag& b2);

}

So based on everything I have seen on line the statement:
class MoneyBag : public bag{ is legal.
As it is done this way on this very site's tutorial:
class Rectangle: public Shape, public PaintCost{

If someone could explain to me specifically what I am in particular doing wrong.
I am even willing for this to be a 'you're an idiot error' as I have wasted a lot of time on this one seemingly minor problem.
Last edited on
class bag is in a namespace try this
class MoneyBag : public main_savitch_3::bag

[EDIT]
also please put your code in codetags its hard to read as is.
Last edited on
Yanson thank you for the help. That fixed it.

Sorry about the formatting issue. The above was my inaugural post. I'm such a noob at the forum and at C++.
Topic archived. No new replies allowed.