我有两个类:MazeClass和CreatureClass,它们使用一个名为"coordinates"的结构,我怎样才能在两个类中使用结构?我试过把结构放两次,我得到:
MazeClass.h:16:8:错误:重新定义'struct coordinate'
CreatureClass.h:11:18:错误:'结构坐标'的先前定义
我想读取数据文件(迷宫),其中我似乎已经编写自己一个赛格错,我承认我是病了我的有关动态分配的大学讲座,并搜查了我的问题throughly,无济于事.这是我的代码片段:
void MazeClass::ReadMaze(ifstream& mazedata) {
mazedata >> row >> column; // Pulls the size from the file
GetExit(mazedata); // Does the same for above, just for the Exit (Required in Class)
GetEntrance(mazedata); // Does the same, just for the entrance (Required in Class)
maze = new char*[row]; // First array of pointers for 2d array
for (unsigned i; i<row;i++)
{ // Creates the second set of arrays
maze[i]=new char[column];
}
for (int y=0;y<column;y++)
{ // Keeping the maze inside boundries …Run Code Online (Sandbox Code Playgroud) 我已经包含了字符串,并且刚刚在头文件中的结构中调用了一个字符串变量.尽管在它之前调用了字符串,但我得到了字符串Origin和Destination City的'string not name a type'
//sortedListClass.h (a few lines of comments)
#include <string>
struct flightRec{
int flightnumber;
string Origin; //problem #1
string DestinationCity; // problem #2
float cost;
flightRec* ptr;
};
typedef flightRec* nodeptr;
#ifndef SORTEDLISTCLASS_H
#define SORTEDLISTCLASS_H
#include <iostream>
#include <cassert>
Run Code Online (Sandbox Code Playgroud)
sortedListClass.h:10:5:错误:'string'没有命名类型
sortedListClass.h:11:5:错误:'string'没有命名类型
我可能会问我做错了什么?