1

Alright, so I have two classes, Vending and Payment. Payment is the child of Vending. I keep getting the "base class undefined" error in my code.

Here are the two header files:

//Parent class (Vending.h)
#ifndef VENDING_H

#define VENDING_H

#include "Main.h";

namespace Vending
{
    class Vending
    {
    public:
        Vending();
        Vending(int);
        void setRequiredAmount(int);
        int getRequiredAmount();


    protected:
        int selectedItem;
        int requiredAmount;
    };
}
#endif VENDING_H

//child class (Payment.h)
#ifndef PAYMENT_H
#define PAYMENT_H

#include "Vending.h"

namespace Vending
{
    class Payment : public Vending
    {
    public:
        Payment(int);
        int getEnteredAmount();
        void setEnteredAmount(int);

        protected:
        int enteredAmount;


    };
}
#endif PAYMENT_H

It would be greatly appreciated if I can get some help to resolve this error

6
  • 2
    Why is Payment.h included in Vending.h?
    – chris
    Mar 24, 2014 at 0:35
  • took it out, still does not solve the issue Mar 24, 2014 at 0:37
  • 2
    and what's #include "Main.h";? and #endif VENDING_H
    – billz
    Mar 24, 2014 at 0:37
  • 1
    After consulting my crystal ball, Main.h includes Payment.h and Vending.h doesn't use anything from Main.h, so it shouldn't include it.
    – chris
    Mar 24, 2014 at 0:38
  • @billz, The #endif VENDING_H is unconventional, but it expands to #endif. Good catch on the semicolon, though. I didn't even see that.
    – chris
    Mar 24, 2014 at 0:38

1 Answer 1

1

You say Main.h includes Payment.h, which DOES lead to circular dependencies. Read this post for additional information: http://forums.codeguru.com/showthread.php?288147-C2504-Base-class-undefined-(other-posts-have-no-solution)&p=919112#post919112

You need to rethink your project properly, conditions like this should not happen. Simply try to remove the #include "Main.h" from the Vending.h, and compile Payment.cpp...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.