【发布时间】:2022-11-17 02:54:08
【问题描述】:
我在单独的文件中有两个 Edge 和 Node 类 边包含节点作为数据
#pragma once
#include<iostream>
#include<vector>
#include"Node.h"
using namespace std;
class Edge
{
public:
Node* parent;
Node* child;
Edge* prev;
Edge(Node* _parent, Node* _child) : parent(_parent), child(_child) { }
static Edge* create(Node* _parent, Node* child);
};
和 节点包含边缘作为数据
#pragma once
#include<iostream>
#include<vector>
//#include"Edge.h"
using namespace std;
class Node
{
public:
//vector<Edge> childern;
virtual void print() = 0 { }
//vector<Edge> extract(Edge* prev); // return children, and set prev to each element in children
};
如何在 Node.h 中包含 Edge.h Edge.h 中的 Node.h 不引起冲突?
我尝试在每个文件的第一行使用#pragma once 但是当我循环时出现了一些错误
Severity Code Description Project File Line Suppression State
Error C2238 unexpected token(s) preceding ';' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 11
Error C2614 'Edge': illegal member initialization: 'child' is not a base or member AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2614 'Edge': illegal member initialization: 'child' is not a base or member AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2614 'Edge': illegal member initialization: 'child' is not a base or member AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2614 'Edge': illegal member initialization: 'parent' is not a base or member AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2614 'Edge': illegal member initialization: 'parent' is not a base or member AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2614 'Edge': illegal member initialization: 'parent' is not a base or member AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2660 'Edge::create': function does not take 2 arguments AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Source.cpp 14
Error C2039 'parent': is not a member of 'Edge' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Source.cpp 15
Error C2065 '_child': undeclared identifier AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2065 '_child': undeclared identifier AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2065 '_child': undeclared identifier AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2065 '_parent': undeclared identifier AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2065 '_parent': undeclared identifier AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2065 '_parent': undeclared identifier AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 11
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 12
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 11
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 12
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 11
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 12
Error C2061 syntax error: identifier 'Node' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2061 syntax error: identifier 'Node' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 14
Error C2061 syntax error: identifier 'Node' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2061 syntax error: identifier 'Node' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 14
Error C2061 syntax error: identifier 'Node' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 13
Error C2061 syntax error: identifier 'Node' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 14
Error C2143 syntax error: missing ';' before '*' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 11
Error C2143 syntax error: missing ';' before '*' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 12
Error C2143 syntax error: missing ';' before '*' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 11
Error C2143 syntax error: missing ';' before '*' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 12
Error C2143 syntax error: missing ';' before '*' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 11
Error C2143 syntax error: missing ';' before '*' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 12
Error C2238 unexpected token(s) preceding ';' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 11
Error C2238 unexpected token(s) preceding ';' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 12
Error C2238 unexpected token(s) preceding ';' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 12
Error C2238 unexpected token(s) preceding ';' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 11
Error C2238 unexpected token(s) preceding ';' AI-Project C:\Users\hazem\source\repos\AI-Project\AI-Project\Edge.h 12
源.cpp
#include<iostream>
#include"Map.h"
#include"Edge.h"
using namespace std;
int main()
{
Node* cairo = new Map("Cairo");
Node* alex = new Map("Alex");
Node* gize = new Map("Giza");
Node* aswan = new Map("Aswan");
Edge* edge = Edge::create(cairo, alex);
edge->parent->print();
return 0;
}
【问题讨论】:
标签: c++