Improper call to function

So I keep getting an error when I try to create an instance of my MazeReader in my main.cpp for an improper call to the function.

main.cpp:8:13: error: no matching function for call to ‘MazeReader::MazeReader()’
  MazeReader MyMaze;
             ^~~~~~


Here is the involved code.

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//main.cpp
#include "MazeReader.h"
#include <string>
using namespace std;
int main(int argc, char* argv[])
{

	MazeReader MyMaze;
        MyMaze.MazeReader(agrv[1]);





	return(0);
}

-------------------------------------------------------------
MazeReader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef MAZE_READER
#define MAZE_READER
#include "MazeCreationException.h"
class MazeReader
{
	public:
        /**
        *       @post A MazeReader is created. A 2D char array is allocated with the 		maze information.
        *       @throws MazeCreationExecption
        *
        */
        MazeReader(std::string ifile) throw (MazeCreationException);

        /**
        *       @post The maze is deallocated.
        */
        ~MazeReader();

        /**
        *       @pre the file was formatting and read in correctly
        *       @return Returns pointer to the maze
        */
        const char* const* getMaze() const;

        /**
        *       @pre the file was formatted and read in correctly
        *       @returns the number of columns listed in the file
        */
        int getCols() const;

        /**
        *       @pre the file was formatted and read in correctly
        *       @returns the number of rows listed in the file
        */
        int getRows() const;

        /**
        *       @pre the file was formatted and read in correctly
        *       @returns the starting column
        */
        int getStartCol() const;

        /**
        *       @pre the file was formatted and read in correctly
        *       @returns the starting row
        */
        int getStartRow() const;

        private:
        /**
        *       @pre the file is properly formatted
        *       @post the characters representing the maze are stores
        */
        void readMaze() throw (MazeCreationException);
};
#endif 

--------------------------------------------------------------------------
MazeReader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <fstream>
#include "MazeReader.h"
#include <string>
#include <sstream>
#include <iostream>
using namespace std;

MazeReader::MazeReader(std::string file) throw (MazeCreationException)
{
	ifstream iFile(file);
	string line;

	while(getline(iFile, line))
	{
	stringstream ss(line);
	
	int rows = 5;
	int cols = 0;

	int startRow = 0;
	int startCol = 0;

	ss>>rows;
	ss>>cols;
	ss>>startRow;
	ss>>startCol;

	cout<<rows;

}

}

MazeReader::~MazeReader()
{

}

const char* const* MazeReader::getMaze() const
{


	return(0);
}

int MazeReader::getCols() const
{


	return(0);
}

int MazeReader::getRows() const
{


	return(0);
}

int MazeReader::getStartCol() const
{


	return(0);
}

int MazeReader::getStartRow() const
{


	return(0);
}

-----------------------------------------------------------------------
Makefile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Maze: main.o MazeWalker.o MazeReader.o
	g++ -std=c++11 -g -Wall main.o MazeWalker.o MazeReader.o -o Maze

main.o: main.cpp MazeWalker.h MazeReader.h
	g++ -std=c++11 -g -Wall -c main.cpp

MazeWalker.o: MazeWalker.h MazeWalker.cpp
	g++ -std=c++11 -g -Wall -c MazeWalker.cpp

MazeReader.o: MazeReader.h MazeReader.cpp
	g++ -std=c++11 -g -Wall -c MazeReader.cpp


clean:
	rm *.o Maze

---------------------------------------------------------------------------
I know most of my methods are not filled in I just started on this and I ran into a problem with the constructor or linking my MazeReader. I figured the MazeWalker code was irrelevant to my problem as there aren't any errors in it and it is even less complete than the MazeReader.
Anyway I was wondering what could be causing me to not be able to make an instance of my MazeReader class in my main.cpp

Any info would be greatly appreciated.
Thanks in advanced!
Last edited on
main.cpp line 8: You instantiate MyMaze using MazeReader's default constructor, but MazeReader has no default constructor.

main.cpp line 9: It looks like you want to invoke MazeReader's constructor that takes a string. That's not how you do it. Try this in place of lines 8-9:
 
	MazeReader MyMaze (agrv[1]);


Topic archived. No new replies allowed.