Well, my code has reached an even more convoluted stage- I need to know how to access a particular element of a class. Sounds simple, except... Well, the object is given to the function as a pointer to the pointer for the object. From there, the element of the class is inside of a pointer to a pointer inside of an object within that passed pointer to a pointer of a class.
I think the code helps a lot:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#ifndef CONNECTOR_H
#define CONNECTOR_H
#include <memory>
#include <utility>
class Vertex;
class Connector
{
public:
Connector();
Connector(Vertex**,Vertex**);
~Connector();
Connector(const Connector& other);
Connector& operator=(const Connector& other);
const std::pair<Vertex**,Vertex**> vertex_pair;
protected:
private:
unsigned int state;
};
namespace std {
template <>
class hash<Connector>{
public :
size_t operator()(const Connector &c ) const{
return hash<Vertex**>()(c.vertex_pair.first) ^ hash<Vertex**>()(c.vertex_pair.second);
}
};
}
#endif // CONNECTOR_H
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#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);
void remove_connection(Connector**);
protected:
private:
unsigned int state;
std::unordered_set<Connector**> connection_set;
};
#endif // VERTEX_H
|
I need to access connection_set, through the objects within vertex_pair, in the function remove_connection. Would it be possible to do it within the vertex proper, or is another function needed to take care of it from the perspective of a connector? If another function (or better yet, the destructor proper) is needed, how would I go about doing so? These pointers hate me right now.
Now, just to specify- the hash function is related to using the Connector class as a key of an unordered_multimap in another, unrelated class. The reason why I'm doing this absurd pointer-to-pointer thing everywhere is because I can't have any vertex or connector actually storing the other- rather, they can only have pointers to the objects stored elsewhere.