2013-03-20 54 views
-1

也许我正在初始化它不正确? 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

错误消息(你获得2个错误和1注意)是相当丰富的......你对'MazeClass :: GetEntrance'的调用,例如'maze.GetEntrance()'缺少一些参数。你对他们有什么不了解? – 2013-03-20 07:01:11

+0

maze.GetEntrance()返回void,不是结构坐标。所以你不能访问像这样的迷宫.GetEntrance()。row。需要一个参数来调用函数GetEntrance – 999k 2013-03-20 07:04:26

回答

1

您想访问main变量Entrance的成员变量。我认为你需要的是这个

coordinate MazeClass::GetEntrance() 
{ 
    return Entrance; 
} 

并相应地改变你的函数原型在头文件。

经过这样的修改您在下面的语句将正常工作(检查()调用col

cout << "The entrance is at: " << maze.GetEntrance().row << " " << maze.GetEntrance().col << endl; 

更改GetExit功能像这样使用它

+0

完美!虚空让我心烦意乱。我担心我需要将它设置为无效。非常感谢 – Volman2014 2013-03-20 07:22:00

1

错误消息实际上告诉你什么是错的:

error: no matching function for call to ‘MazeClass::GetEntrance()’ 
                   ^^^^^ 

您提供的功能是:

void MazeClass::GetEntrance(coordinate Entrance) 
          ^^^^^^^^^^^^^^^^^^^^^^ 

注意上面的^^^^^^

正如你所看到的两个函数不一样!
你声明并定义了一个我thod以coordinate对象作为参数,但是您调用的方法不会接受任何参数,显然编译器不会找到任何此类方法并且适当地投诉。

+0

当我将(坐标入口)放入我的.cc文件中的函数调用时,它给了我这个错误ola4A1.cc:在函数'int main(int,char **)'中: ola4A1 .cc:17:错误:在'入口'之前预期的初级表达式 ola4A1.cc:17:错误:在入口之前期望的初级表达式 – Volman2014 2013-03-20 07:06:52

+0

@JohnSmith:*你真的不理解编程和C++的基础知识* 。在理解它们之前,你不应该问这里的问题(因为教C++需要很多时间,而且我们没有那么多)。进入你的大学图书馆,**需要花费很多时间阅读有关使用C++编程的优秀书籍。......试图对“随机”进行编码并希望它偶尔能够正常工作并不是学习编程的好途径。 – 2013-03-20 08:02:25

1

你的GetEntrance定义说,它预计(类型coordinate)的一个参数。

如果你尝试调用它,你是不是传递一个参数,所以它在寻找一些其他的过载,可以不带参数调用。

另外请注意,您可能maze.GetEntrance.col必须maze.GetEntrance().col代替。

1

1)您正在致电maze.GetEntrance(),但MazeClass没有GetEntrance()方法。只有MazeClass::GetEntrance(coordinate)

2)您致电maze.GetEntrance().row表明您期望MazeClass::GetENtrance()返回一些东西。目前返回voidvoid没有会员row

相关问题