<分区>
我在 2 个不同的文件中编写了 2 个类:router.h - router.cpp 和 topology.h - topology.cpp。
我将展示 .h 文件的内容,因为 .cpp 文件仅包含实现。
路由器.h:
#ifndef _ROUTER_H_
#define _ROUTER_H_
#include <map>
#include "topology.h"
using namespace std;
class Router {
public:
int id;
map<Router, int> linkers;
Topology topology;
Router();
Router(int id);
void addLink(Router router, int cost);
void delLink(Router router);
};
#endif
拓扑.h:
#ifndef _TOPOLOGY_H_
#define _TOPOLOGY_H_
#include "router.h"
class Topology {
public:
map<Router, int> graph;
Topology();
void addNode(Router router, int cost);
void delNode(Router router);
};
#endif
我的问题是,为什么在编译时出现由无法识别的 Router 和 Topology 类引起的错误,即使我包含了 header 并添加了 ifndefs 以便不包含多个文件?我在互联网上查找,也在堆栈上查找,但没有发现任何关于这个问题的信息。