簡體   English   中英

未解析的外部符號“類”

[英]Unresolved External symbol “class”

錯誤 LNK2001無法解析的外部符號“類對象對象”

當將該類聲明為extern時,它將為連接到它的每一段代碼創建此鏈接器錯誤。 但是,當我在其他文件中創建該類的私有版本時,它們可以正常工作。

更改類變量的名稱無效,因此它不會與導致錯誤的映射系統沖突。

我看不到並修改錯誤。 以前它在工作,我撤消了文件,希望它能再次運行,但沒有。

Object.cpp

#include "object.h"

#include "Ball.h"

// Constructor
Object::Object() {

    std::map<int, std::map<int, IMAGEINFO>> object;

};

Object::~Object() {

    object.clear();

};    

void Object::Update() {

    // Gets all the base object ID's
    for (unsigned int i = 0; i < object.size(); i++) {

    // Gets all the object's inside that ID.
        for (unsigned int j = 0; j < object[i].size(); j++) {

            // Gets the object.
            IMAGEINFO obj = object[i][j];

            // Calls for the processes of the object
            obj.Update();
        }
    }
}

void Object::Render(HDC hdc, RECT* prc, BITMAP bm) {

    // Gets all the base object ID's
    for (unsigned int i = 0; i < object.size(); i++) {

        // Gets all the object's ID's. 
        for (unsigned int j = 0; j < object[i].size(); j++) {

            // Gets the object.     
            IMAGEINFO obj = object[i][j];

            // Calls for the rendering of the object        
            obj.Render(hdc, prc, bm);

        }
    }
}

int Object::addObject(IMAGEINFO obj) {

    bool index = false;
    int indexVal;
    short run = 0;

    while (!index) {

        if (typeid(obj).name() == typeid(object[run]).name()) {

            object[run][object[run].size()] = obj;
            indexVal = object[run].size();
            index = true;

        }
        else if (run == object.size()) {

            object[run][0] = obj;
            indexVal = 0;
            index = true;

        }

        run++;

    }

    return indexVal;

}

對象

#ifndef OBJECT_H
#define OBJECT_H
#endif

#include <windows.h>
#include <iostream>
#include <map>

#include "renderer.h"
#include "resource.h"

class Object {
public:

    // Constructors/Deconstructors
    Object();
    ~Object();

    // Processes
    int addObject(IMAGEINFO value);
    void Update();
    void Render(HDC hdc, RECT* prc, BITMAP bm);

private:

    std::map<int, std::map<int, IMAGEINFO>> object;

};

extern Object objects;

球cpp

#include "Ball.h";

int indexPos;

HBITMAP hbm_Ball_Image = NULL;
HBITMAP hbm_Ball_Mask = NULL;

IMAGEINFO ballInfo;

void Ball(BITMAP bm, int assx, int assy) {

    indexPos = objects.addObject(ballInfo);

    hbm_Ball_Image = createImage((HBITMAP) BITMAP_BALL);
    hbm_Ball_Mask = createMask((HBITMAP)BITMAP_BALL, RGB(255, 255, 255), bm);

    GetObject(hbm_Ball_Image, sizeof(bm), &bm);

    ballInfo.height = bm.bmHeight;
    ballInfo.width = bm.bmWidth;

    ballInfo.x = assx;
    ballInfo.y = assy;

    ballInfo.speedX = 1;
    ballInfo.speedY = 0;

}

#ifndef BALL_H
#define BALL_H
#endif

#include <windows.h>
#include <iostream>
#include <map>

#include "renderer.h"
#include "resource.h"
#include "object.h"

void Ball(BITMAP bm, int assx, int assy);
void render(HDC hdc, RECT* prc, BITMAP bm);

Object objects;  // construct an instance of the class

到文件Object.cpp的末尾

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM