I have two (really three, but one is irrelevant here) header files with classes in them for a project. One Node
class that includes a set of pointers to other nodes (its like a tree), and the other class is a graph class (entitled AML
) that holds a set of all the pointers to nodes in their respective layers.
I wanted to write my own C++ set operations (because I'll need them), so I decided to declare a namespace that has the set operation functions. However when I try to use these set operations in my Node
class, I get an error. Here is the relevant code:
aml.h
#pragma once
#include <set>
#include "Node.h"
#include "constant.h"
using namespace std;
class aml
{
// class stuff
};
namespace setops {
set<Node*> set_union(set<Node*> &a, set<Node*> &b);
// other set operations
}
aml.cpp
#include "aml.h"
using namespace std;
//class functions
set<Node*> setops::set_union(set<Node*> &a, set<Node*> &b) {
set<Node*> c;
for (Node* data : a) {
c.insert(data);
}
for (Node* data : b) {
c.insert(data);
}
return c;
}
Node.h
#pragma once
#include <string>
#include <set>
#include "aml.h"
#include "constant.h"
using namespace std;
class Node
{
private:
set<Node*> lower;
public:
set<Node*> getLower();
set<Node*> GL();
};
and here is the GL()
method in which the error occurs. This is supposed to return the set of all nodes that can be reached by traveling down the tree. getLower()
returns the lower
set that houses all a node's children.
Node.cpp
#include "Node.h"
set<Node*> Node::getLower() {
return this->lower;
}
set<Node*> Node::GL() {
set<Node*> lowerSet;
lowerSet.insert(this);
if (this->lower.size() == 0) {
return lowerSet;
}
set<Node*> recurse;
for (Node* node : this->lower) {
recurse = node->GL();
lowerSet = setops::set_union(lowerSet, recurse); //This is the error line
}
return lowerSet;
}
I marked the problem line. It actually has three errors, one on each parameter and one of the equals sign. The errors say (all of them are pretty much the same, but this is the parameter one)
a reference of type "set::set<<error-type>*, std::less<<error-type>*>, std::allocator<<error-type>*>& "(non-const qualified) cannot be initialized with a value of type "set::set<Node*, std::less<Node*>, std::allocator<Node*>> "
I have no idea what is going on, any help appreciated!