Derived class - 'class' was not declared in this scope

Hello,

I am receiving an error: "'binST' and 'bst' was not declared in this scope when it tries creating an object from a derived class. I'm not quite sure what I am missing...

Here is the base structure for my program, I have pulled out irrelevant information.

below is 'b1.h'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "b2.h"

class Node {
    friend class binT;
    friend class binST;

    public:
        Node();
};


class binT {
    public:
        binT();
};


below is 'b2.h'
1
2
3
4
5
6
#include "b1.h"

class binST : public binT{
    public:
        binST() : binT() {}
};


below is code for 'main.cc'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

#include "b1.h"
#include "b2.h"

using std::cout;

void showInfo(binST& bst) {  //ERROR - binST and bst were not declared in this scope
  std::cout << "test";
}

int main () {

binST bst  //create an object of binST
showInfo(bst);

return 0;
}
Last edited on
One problem is that you have a circular dependency. b1.h includes b2.h and b2.h includes b1.h. There is no reason, as far as I can see, for b1.h to include b2.h.
Last edited on
Topic archived. No new replies allowed.