I have a class (Quadtree) and three inner class inside (Node, Inner and Leaf). Inner and Leaf inherit from Node.
I have a function in the private scope of Quadtree.
All these are located in fun.h .
Then, in fun.cpp, I am implementing the function (which is named foo <- what a prototype name!), which takes as argument a pointer to an Inner object. Inner seems unable to be resolved however!
fun.h
Code:
class Quadtree {
private:
class Node{
public:
Node() { std::cout << "Node\n"; }
};
class Inner : public Node {
public:
Inner() { std::cout << "Inner\n"; }
friend class Quadtree;
};
class Leaf : public Node {
public:
Leaf() { std::cout << "Leaf\n"; }
friend class Quadtree;
};
int foo(Inner* p);
public:
Quadtree() { std::cout << "Quadtree\n"; }
};
fun.cpp
Code:
#include <iostream>
#include "fun.h"
int foo(Inner* p) { std::cout << "foo\n"; }
px.cpp
Code:
#include <iostream>
#include "fun.h"
int main()
{
Quadtree tree;
return 0;
}
Compilation & error:
Code:
samaras@samaras-A15:~$ g++ px.cpp fun.cpp -o px
fun.cpp:4:9: error: ‘Inner’ was not declared in this scope
fun.cpp:4:16: error: ‘p’ was not declared in this scope
fun.cpp:4:19: error: expected ‘,’ or ‘;’ before ‘{’ token