Maybe I am initializing it incorrectly? Preety sure this is how our teacher showed us how to do it.. but im stumped. I am trying to use the function as an accessor and get the data and display what is already stored in the struct "coordinate" under the member "Entrance"
Header file:
#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
Implementation file:
#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)
{
}
and my file to try and use it:
#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;
}
and im getting this error:
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
I have tried placing coordinate in like this:
#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;
}
but i THEN get the error:
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
AFTER which... I added in "Entrance" like so..
#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;
}
and it gives me this error...
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’
So YES... I am stumped...Any help would be greatly appreciated! I have been trying to figure this one out for an hour now :(
You want to acces member variables of variable Entrance
in main. i think what you need is this
coordinate MazeClass::GetEntrance()
{
return Entrance;
}
And change you function prototype in header file accordingly.
With this modification your below statement will work fine (check ()
for calling col
)
cout << "The entrance is at: " << maze.GetEntrance().row << " " << maze.GetEntrance().col << endl;
Change your GetExit
function also like this for using it