这个编译错误是什么?

时间:2015-03-05 18:22:22

标签: c++ compiler-errors

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

  

1> main.obj:错误LNK2019:Verweis aufnichtaufgelöstesexternes   符号“”public:void __thiscall Area :: createArea(void)“   (?createArea @ Area @@ QAEXXZ)“在Funktion”_main“。1> D:\ C ++   Projekte \ EREBOS_2 \ Debug \ EREBOS_2.exe:致命错误LNK1120:1 nicht   aufgelösteexterneVerweise。

英文翻译:

  

1> main.obj:错误LNK2019:未解析的符号“”的外部引用   public:void __thiscall Area :: create area(void)“(?创建区域   区域@@@ 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();
}

1 个答案:

答案 0 :(得分:2)

该消息表示您尝试调用&#34; public:void __thiscall Area :: createArea(void)&#34;但是后来链接器找不到该功能。

我看到的最接近的是MainArea.createArea(); - 我猜你要么没有实现这个功能(在Area.cpp中,你没有告诉我们),或者你只是没有链接Area.o,或者没有以所需的顺序。

请参阅What is an undefined reference/unresolved external symbol error and how do I fix it?