unordered_set, smart_ptr and classes, oh my!

Well, this is a bit of a frustrating issue- I am trying to create two classes that both contain containers of smart pointers to the other class. So far, I have one that works fine:

std::pair<std::shared_ptr<Vertex>,std::shared_ptr<Vertex>> vertex_pair;

That works with no issue in Connector.h. However, the moment I try to do the same with an unordered_set in Vertex.h...

std::unordered_set<std::shared_ptr<Connector>> connection_set;

I get an error saying that Connector was not declared. I doubt this is due to a failed #include, since they follow the same format other than the name of what is being included (and it works fine for one but not the other). The code itself is incomplete, but I'd rather be dealing with this issue now rather than later. Here's the full code for both:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef CONNECTOR_H
#define CONNECTOR_H
#include <memory>
#include <utility>
#include "Vertex.h"

class Connector
{
    public:
        Connector();
        ~Connector();
        Connector(const Connector& other);
        Connector& operator=(const Connector& other);
    protected:
    private:
        unsigned int state;
        std::pair<std::shared_ptr<Vertex>,std::shared_ptr<Vertex>> vertex_pair;
};

#endif // CONNECTOR_H 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef VERTEX_H
#define VERTEX_H
#include <memory>
#include <unordered_set>
#include "Connector.h"

class Vertex
{
    public:
        Vertex();
        ~Vertex();
        Vertex(const Vertex& other);
        Vertex& operator=(const Vertex& other);
    protected:
    private:
        unsigned int state;
        std::unordered_set<std::shared_ptr<Connector>> connection_set;
};

#endif // VERTEX_H 
Vertex.h includes Connector.h and Connector.h includes Vertex.h
http://www.cplusplus.com/articles/Gw6AC542/
That article helped perfectly. Thanks! All it took was a bit of forward-declaration instead of includes.
What was your (now deleted) post about merging into one class about?
Oh, it was me completely misunderstanding what a forward declaration is.
Topic archived. No new replies allowed.