Программы на C++. Форум разработчиков
Anonymous
Разрешение циклических зависимостей в определениях классов
Сообщение
Anonymous » 21 июн 2024, 16:12
Для моей небольшой программы мне нужен класс, представляющий узел неориентированного графа. Выглядит это так:
Код: Выделить всё
#ifndef DIRECTED_GRAPH_NODE_H
#define DIRECTED_GRAPH_NODE_H
#include
#include
#include
#include
#include
class DirectedGraphNode;
class DirectedGraphNode {
private:
std::size_t m_id;
std::unordered_set* m_neighbors;
public:
DirectedGraphNode(std::size_t id)
: m_id{ id }
, m_neighbors{ new std::unordered_set} {}
std::unordered_set* getNeighbors() {
return m_neighbors;
}
void addNeighbor(DirectedGraphNode& neighbor) {
m_neighbors->insert(&neighbor);
}
bool operator==(DirectedGraphNode* other) {
return m_id == other->m_id;
}
friend std::ostream& operator
Подробнее здесь: [url]https://stackoverflow.com/questions/78646927/resolving-cyclic-dependencies-in-class-definitions[/url]
1718975533
Anonymous
Для моей небольшой программы мне нужен класс, представляющий узел неориентированного графа. Выглядит это так: [code]#ifndef DIRECTED_GRAPH_NODE_H #define DIRECTED_GRAPH_NODE_H #include #include #include #include #include class DirectedGraphNode; class DirectedGraphNode { private: std::size_t m_id; std::unordered_set* m_neighbors; public: DirectedGraphNode(std::size_t id) : m_id{ id } , m_neighbors{ new std::unordered_set} {} std::unordered_set* getNeighbors() { return m_neighbors; } void addNeighbor(DirectedGraphNode& neighbor) { m_neighbors->insert(&neighbor); } bool operator==(DirectedGraphNode* other) { return m_id == other->m_id; } friend std::ostream& operator Подробнее здесь: [url]https://stackoverflow.com/questions/78646927/resolving-cyclic-dependencies-in-class-definitions[/url]