小编Ath*_*ius的帖子

C++:跨类的结构

我有两个类:MazeClass和CreatureClass,它们使用一个名为"coordinates"的结构,我怎样才能在两个类中使用结构?我试过把结构放两次,我得到:

MazeClass.h:16:8:错误:重新定义'struct coordinate'

CreatureClass.h:11:18:错误:'结构坐标'的先前定义

c++ struct class

3
推荐指数
1
解决办法
3337
查看次数

使用iostream和指针获取Seg Fault

我想读取数据文件(迷宫),其中我似乎已经编写自己一个赛格错,我承认我是病了我的有关动态分配的大学讲座,并搜查了我的问题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)

c++

1
推荐指数
1
解决办法
107
查看次数

include string,string不命名类型

我已经包含了字符串,并且刚刚在头文件中的结构中调用了一个字符串变量.尽管在它之前调用了字符串,但我得到了字符串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'没有命名类型

我可能会问我做错了什么?

c++ string include

0
推荐指数
1
解决办法
1768
查看次数

标签 统计

c++ ×3

class ×1

include ×1

string ×1

struct ×1