我有這個鼠標和迷宮程序,我爲鼠標和迷宮定義了一個單獨的類。我在每個類的頭文件中包含了其他類頭文件。在鼠標中,如果我通過引用迷宮(如此功能(迷宮& myMaze,鼠標& myMouse)它檢查出好。如果我在迷宮中做同樣的事情,它說不是那種類型。我解決這個問題在類中傳遞類C++
從迷宮CPP:
void maze::initialize_map(mouse& myMouse) {} (error of previous mention)
從小鼠CPP:
string mouse::get_movement(maze& myMaze, mouse& myMouse) {} (no error)
鼠標頭:
#ifndef MOUSE_H
#define MOUSE_H
#include <cstring>
#include <string>
#include <iostream>
#include <fstream>
#include "maze.h"
class mouse {
private:
int life, locationX, locationY, toLocX, toLocY, los_max_distance;
char los_direction;
bool sight;
public:
mouse(): life(50), locationX(0), locationY(0), toLocX(0), toLocY(0), los_max_distance(0), los_direction('0'), sight(false) {}
int get_life() const;
int get_locationX() const;
int get_locationY() const;
bool get_sight() const;
std::string get_movement(maze&, mouse&);
void set_life(int);
void set_location(int, int, maze&);
void set_sight();
void unset_sight();
void set_path(char);
void set_distance(char);
};
#endif /* MOUSE_H */
迷宮標題:
#ifndef MAZE_H
#define MAZE_H
#include <cstring>
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stack>
#include "mouse.h"
class maze {
private:
static const int MAX_LENGTH = 20;
static const int MAX_WIDTH = 20;
char board[MAX_LENGTH][MAX_WIDTH];
char wall, open, mouse, cheese;
int lastIntersectionX, lastIntersectionY, locationMX, locationMY, locationCX, locationCY, last_room;
bool scent;
std::stack <int> lastDirection;
struct directions {
std::string direction[4], next, prev;
int longest, length[4];
} movement;
public:
maze(): wall('+'), open('.'), mouse('m'), cheese('c'), lastIntersectionX(0), lastIntersectionY(0), locationMX(0), locationMY(0), locationCX(0), locationCY(0), last_room(0), scent(false) {
for (int i = 0; i < 20; ++i) {
for (int k = 0; k < 20; ++k) {
board[i][k] = '0';
}
}
for (int i = 0; i < 4; ++i) {
movement.direction[i] = "none";
movement.length[i] = 0;
}
movement.next = "none", movement.prev = "none", movement.longest = 0;
};
void initialize_map(mouse&);
void view_map() const;
char get_map_room(char, char) const;
void set_map_room(int, int, char);
void line_of_sight(maze&, mouse&);
void get_exit(maze&, mouse&);
std::string get_next(maze&, mouse&) const;
std::string get_prev(maze&, mouse&) const;
int get_longest() const;
int get_mouse_locationX() const;
int get_mouse_locationY() const;
void view_location() const;
void set_mouse_location(int, int);
void set_cheese_location(int, int);
};
#endif /* MAZE_H */
注意:這是我的課實驗室。但是,這個特殊的問題與它無關。教授告訴我,我比我更努力,而且我很可能,但我很樂意以這種方式完成這項工作,我想繼續。如果我能讓這兩個人傳遞信息,我可以繼續我的項目。
爲什麼不讓運動變成一個枚舉而不是一個字符串? – 2014-10-31 15:02:32
您不包括確切的錯誤消息。 – 2014-10-31 15:03:24
我沒有看到你在哪裏調用該方法。您還應該確保顯示確切的錯誤信息。 – crashmstr 2014-10-31 15:03:38