也许我正在初始化它不正确? Preety肯定这是我们的老师向我们展示了如何做到这一点的方式..但我很难过。我想使用的功能作为访问和获取数据并显示哪些已经被存储在下面的成员“入口”错误:没有用于调用我的类对象的匹配函数
头文件中的结构“协调”:
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
#include "type.h"
const int MAX = 50;
#ifndef MazeClass_H
#define MazeClass_H
class MazeClass
{
private:
SquareType Maze[MAX][MAX];
coordinate Entrance, Exit;
int height, width;
public:
MazeClass();
void ReadMaze(ifstream&);
void DisplayMaze();
void GetEntrance(coordinate);
void GetExit(coordinate);
void MarkVisited(coordinate);
void MarkPath(coordinate);
bool IsWall(coordinate);
bool IsClear(coordinate);
bool IsPath(coordinate);
bool IsVisited(coordinate);
bool IsExit(coordinate);
bool IsInMaze(coordinate);
};
#endif
实现文件:
#include "MazeClass.h"
#include <iostream>
#include <cstdlib>
char maze[50][50];
MazeClass::MazeClass()
{
}
void MazeClass::ReadMaze(ifstream& myIn)
{
int x, y;
myIn >> x;
myIn >> y;
height = x;
width = y;
myIn >> x;
myIn >> y;
Entrance.row = x;
Entrance.col = y;
myIn >> x;
myIn >> y;
Exit.row = x;
Exit.col = y;
myIn.ignore(100, '\n');
for(int i = 0; i < height; i++)
{
for(int k = 0; k < width + 1; k++)
{
myIn.get(maze[i][k]);
if(maze[i][k] == '*')
Maze[i][k] == Wall;
else
Maze[i][k] == Clear;
}
}
}
void MazeClass::DisplayMaze()
{
for(int i = 0; i < height; i++)
{
for(int k = 0; k < width + 1; k++)
{
cout << maze[i][k];
}
}
}
void MazeClass::GetEntrance(coordinate Entrance)
{
}
void MazeClass::GetExit(coordinate Exit)
{
}
,我的文件,试图使用它:
#include "MazeClass.h"
#include<iostream>
#include<fstream>
using namespace std;
int main(int argc,char *argv[])
{
MazeClass maze;
ifstream myIn;
int x,y;
string filename = argv[1]; // command line arguement stuff
myIn.open(filename.c_str());
maze.ReadMaze(myIn); //reads in the maze from a data file
maze.DisplayMaze();
cout << "The entrance is at: " << maze.GetEntrance().row << " " << maze.GetEntrance.col << endl;
myIn.close();
return 0;
}
和IM总体性他的错误:
ola4A1.cc:17: error: no matching function for call to ‘MazeClass::GetEntrance()’
MazeClass.h:21: note: candidates are: void MazeClass::GetEntrance(coordinate)
ola4A1.cc:17: error: ‘maze.MazeClass::GetEntrance’ does not have class type
我试图把坐标如下:
#include "MazeClass.h"
#include<iostream>
#include<fstream>
using namespace std;
int main(int argc,char *argv[])
{
MazeClass maze;
ifstream myIn;
int x,y;
string filename = argv[1]; // command line arguement stuff
myIn.open(filename.c_str());
maze.ReadMaze(myIn); //reads in the maze from a data file
maze.DisplayMaze();
cout << "The entrance is at: " << maze.GetEntrance(coordinate).row << " " << maze.GetEntrance(coordinate).col << endl;
myIn.close();
return 0;
}
但我当时得到的错误:
ola4A1.cc: In function ‘int main(int, char**)’:
ola4A1.cc:17: error: expected primary-expression before ‘)’ token
ola4A1.cc:17: error: expected primary-expression before ‘)’ token
之后......我在“高考加“像这样..
#include "MazeClass.h"
#include<iostream>
#include<fstream>
using namespace std;
int main(int argc,char *argv[])
{
MazeClass maze;
ifstream myIn;
int x,y;
string filename = argv[1]; // command line arguement stuff
myIn.open(filename.c_str());
maze.ReadMaze(myIn); //reads in the maze from a data file
maze.DisplayMaze();
cout << "The entrance is at: " << maze.GetEntrance(coordinate Entrance).row << " " << maze.GetEntrance(coordinate Entrance).col << endl;
myIn.close();
return 0;
}
它给我提供s的错误...
ola4A1.cc: In function ‘int main(int, char**)’:
ola4A1.cc:17: error: expected primary-expression before ‘Entrance’
ola4A1.cc:17: error: expected primary-expression before ‘Entrance’
所以是......我很难过...任何帮助将不胜感激!我一直在努力,现在推测这一个一个小时:(
错误消息(你获得2个错误和1注意)是相当丰富的......你对'MazeClass :: GetEntrance'的调用,例如'maze.GetEntrance()'缺少一些参数。你对他们有什么不了解? – 2013-03-20 07:01:11
maze.GetEntrance()返回void,不是结构坐标。所以你不能访问像这样的迷宫.GetEntrance()。row。需要一个参数来调用函数GetEntrance – 999k 2013-03-20 07:04:26