Fatal Error When Calling A Function From A Class Object

0

I'm trying to get started on a program that has to read from a file and in trying to call a function on an object I get fatal error code. I've only determined that this is the source of the error because I deleted all the code in my .cpp file except for empty function bodies and it still produced the same error. Ultimately all I'm trying to do with this code is test if I can read in two separate lines from a file, which holds two ints, splits them prints the ints then continues to print each line of the file that are no longer ints to the console. Sorry if my title is misleading, I'm not fully sure of what problem I have here.

a file example would be as so:

10 7  
6  2
##########          
#  ###   #
#  #     #
#        #
#        #
#        #
## #######         

here is my Ass3Main file code:

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <istream>
#include <string>
#include "Maze.h"

using namespace std;

int main()
{
    Maze m;
    m.readFile("mazeSimple.txt");
    return 0;
}

Here is my Maze.cpp code

//
// Created by Evan Walkoski on 10/22/2019.
//

#include "Maze.h"
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <istream>
#include <string>
#include <sstream>
#include <iterator>
#include <vector>

using namespace std;

void readFile(string filename)
{
    string line;
    ifstream myfile(filename);
    if (myfile.is_open())
    {
        getline(myfile, line);
        istringstream iss(line);
        vector<std::string> results((std::istream_iterator<std::string>(iss)),
                                    std::istream_iterator<std::string>());
        for (int i = 0; i < results.size(); i++)
        {
            cout << results[i] << endl;
        }
        cout << "~~~~~~~~~~~~~~" << endl;
        getline(myfile, line);
        istringstream iss2(line);
        for (int i = 0; i < 10; i++)
        {
            getline(myfile, line);
            cout << line << endl;
        }
        myfile.close();
    }
    else
        cout << "Unable to open file";
}

Here is my Maze.h code

//
// Created by Evan Walkoski on 10/22/2019.
//

#ifndef ASS3_MAZE_H
#define ASS3_MAZE_H
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <istream>
#include <string>

using namespace std;

class Maze
{
    public:
        void readFile(string filename);
};


#endif //ASS3_MAZE_H

Here is the error code:

Scanning dependencies of target ass3
[ 33%] Building CXX object CMakeFiles/ass3.dir/Maze.cpp.obj
Maze.cpp
[ 66%] Linking CXX executable ass3.exe
LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1422~1.279\bin\Hostx86\x86\link.exe /nologo @CMakeFiles\ass3.dir\objects1.rsp /out:ass3.exe /implib:ass3.lib /pdb:C:\Users\Evan Walkoski\Documents\CSS\CSS 342\ass3\cmake-build-debug\ass3.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\ass3.dir/intermediate.manifest CMakeFiles\ass3.dir/manifest.res" failed (exit code 1120) with the following output:
Ass3Main.cpp.obj : error LNK2019: unresolved external symbol "public: void __thiscall Maze::readFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?readFile@Maze@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
ass3.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2019.2.2\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
c++
function
class
object
fatal-error
asked on Stack Overflow Oct 22, 2019 by (unknown user)

1 Answer

0

Sorry, the comment posted by UnholySheep

"void readFile is not the same as void Maze::readFile"

solved my problem. I started using c++ coming from java so I still do stupid things like this. Changing the function header in my .cpp file to void Maze::readFile fixed the problem.

answered on Stack Overflow Oct 22, 2019 by (unknown user)

User contributions licensed under CC BY-SA 3.0