这个编译错误是什么

What is this compilation error?

本文关键字:是什么 错误 编译      更新时间:2023-10-16

在尝试编译时,我收到以下错误:

1> main.obj:错误LNK2019:Verweis auf nicht aufgelöstes externes符号"public:void __thiscall Area::createArea(void)"(?createArea@Area@@QAEXXZ)"在函数"_main".1>D:\C++Projekte\EREBOS_2\Debug\EREBOS_2.exe:致命错误LNK1120:1 nicht外部Verweise。

英文翻译:

1> main.obj:错误LNK2019:对符号"的未解析外部引用public:void __thiscall区域::创建区域(void)"(?创建区域Area@@@QAEXXZ)"函数在"_main"1>D:.\C++Projects\EREBOS_2\Debug\EREBOS_2.exe:致命错误LNK1120:1个未解析的外部。

这是什么意思?我该怎么修?

代码:

#include <iostream>
#include "windows.h"
#include "MainMenu.h"
#include "MainPlayer.h"
#include <ctime>
#include <string>
int y;
int x;
using namespace std;
void createArea()
{
    int area[15][15];
    for(int y = 0; y < 15; y++)
    {
        for (int x = 0; x < 15; y++)
        {
            area[x][y] = 0;
        }
    }
    //---------------------------------
    for(int counter = 0; counter < 15; counter++)
    {
        area[1][y] = 1;
        area[15][y] = 1;
    }
    //--------------------------------------
    for (int y = 0; y <15; y++)
    {
        for (int x = 0; x < 15; x++)
        {
            cout << area[x][y];
        }
    }
}

#include <iostream>
#include "windows.h"
#include "MainMenu.h"
#include <ctime>
#include <string>
using namespace std;
void MainMenu:: createMenu()
{
    int typed;
    system("cls");
    cout << endl;
    cout << endl;
    cout << "   --------------" << endl;
    cout << "   | 1) Start   |" << endl;
    cout << "   | 2) Hilfe   |" << endl;
    cout << "   | 3) Credits |" << endl;
    cout << "   | 4) Beenden |" << endl;
    cout << "   --------------" << endl;
    cin >> typed;
    if(typed == 1)
    {
        cout << "...still a whole lot of work to do..." << endl;
    }
}

#include <string>
class MainMenu
{
public:
    void createMenu();
};

#include <iostream>
#include "windows.h"
#include "MainMenu.h"
#include "MainPlayer.h"
#include <ctime>
#include <string>
using namespace std;
void Mainplayer:: showData()
{
    using namespace std;
    int health = 100;
    int xp = 0;
    int lvl = 1;
    int gold = 10;
    std:: string Name = "Namenloser";
    system("cls");
    cout << "-----------------------" << endl;
    cout << "Name: " << Name << endl;
    cout << "Leben: " << health << "/100" << endl;
    cout << "Erfahrung: " << xp << "/" << lvl*10 << endl;
    cout << "Level: " << lvl << "/50" << endl;
    cout << "Gold: " << gold << endl;
    cout << "------------------------" << endl;
}

#include <string>
class Mainplayer
{
    public:
        int health;
        int xp;
        int lvl;
        int gold;
        std:: string Name;
        void showData();
        int playercoordy;
        int playercoordx;
};

#include <iostream>
#include "windows.h"
#include "MainMenu.h"
#include "MainPlayer.h"
#include "Area.h"
#include <ctime>
#include <string>
using namespace std;
void maingame();
int main()
{
    system("title EREBOS 2");
    Mainplayer MainChar; 
    MainMenu menu;
    Area MainArea; 
    menu.createMenu();
    MainChar.showData();
    MainArea.createArea();
    getchar();
    getchar();
}

该消息意味着您尝试调用"public:void __thiscall-Area::createArea(void)",但链接器找不到该函数。

我看到的最接近的是MainArea.createArea();-我猜,要么你还没有实现这个功能(在Area.pp中,你没有向我们展示),要么你只是没有链接Area.o,要么没有按照所需的顺序。

请参阅什么是未定义的引用/未解决的外部符号错误,以及如何修复它?