C++ 从类对象调用函数时发生致命错误

C++ 从类对象调用函数时发生致命错误,c++,function,class,object,fatal-error,C++,Function,Class,Object,Fatal Error,我试图开始一个必须从文件中读取的程序,在试图调用对象上的函数时,我得到了致命的错误代码。我只确定这是错误的来源,因为我删除了.cpp文件中除空函数体之外的所有代码,但仍然产生了相同的错误。最终,我要做的就是测试我是否可以从一个文件中读取两行,其中包含两个int,拆分它们,打印int,然后继续将不再是int的文件的每一行打印到控制台。对不起,如果我的标题有误导性,我不完全确定我这里有什么问题 文件示例如下所示: 10 7 6 2 ########## # ### #

我试图开始一个必须从文件中读取的程序,在试图调用对象上的函数时,我得到了致命的错误代码。我只确定这是错误的来源,因为我删除了.cpp文件中除空函数体之外的所有代码,但仍然产生了相同的错误。最终,我要做的就是测试我是否可以从一个文件中读取两行,其中包含两个int,拆分它们,打印int,然后继续将不再是int的文件的每一行打印到控制台。对不起,如果我的标题有误导性,我不完全确定我这里有什么问题

文件示例如下所示:

10 7  
6  2
##########          
#  ###   #
#  #     #
#        #
#        #
#        #
## #######         
这是我的助理3主文件代码:

#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;
}
#包括
#包括
#包括
#包括
#包括
#包括“Maze.h”
使用名称空间std;
int main()
{
迷宫m;
m、 readFile(“mazeSimple.txt”);
返回0;
}
这是我的Maze.cpp代码

//
// 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";
}
//
//由Evan Walkoski于2019年10月22日创建。
//
#包括“Maze.h”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
void readFile(字符串文件名)
{
弦线;
ifstream myfile(文件名);
如果(myfile.is_open())
{
getline(myfile,line);
istringstream iss(线);
向量结果((std::istream_迭代器(iss)),
std::istreamu迭代器();
对于(int i=0;i对不起,这是邪恶羊发布的评论

“void readFile与void Maze::readFile不同”


解决了我的问题。我开始使用C++来做java的事,所以我还是做了一些愚蠢的事情。把我的.CPP文件中的函数头改成迷宫::Read Frfile修复了这个问题。

StEnoTo:使用<代码> <代码>代替<代码> <代码>空读文件不与VuleMase::Read Frime<代码> >
//
// 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
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.