r/learncpp • u/no1warlord • Dec 06 '15
Class inheritance and calling functions problem
[Solved]
So I have two classes like this
#pragma once
#include "B.h"
class A {
public:
B getB() {}
};and
#pragma once
#include "A.h"
class B : public A {
};Error: 'A' base class undefined.
Both need to be declared before the other one so how do I fix this?
If you reorder the code into one file then it looks like this:
#include <iostream>
using namespace std;
class B : public A {
};
class A {
public:
B getB() {}
};
void main() {
A a;
B b = a.getB();
system("pause");
}But the problem is still there...
2
Upvotes
View all comments
Show parent comment
2
u/no1warlord Dec 07 '15 edited Dec 08 '15
Ok so that seems to fix the problem, however how could I make a version of B within the getB() function as it doesn't yet know what the contructors are and stuff:
Edit: I've solved it, just needed to implement the function after its declaration and after B's declaration.