C++ 未解析的外部符号“;“类”;
错误 LNK2001未解析外部符号“类对象” 当类被声明为外部时,它将为连接到它的每段代码创建此链接器错误。但当我在其他文件中创建该类的私有版本时,它们工作正常 更改类变量的名称无效,因此不会与导致错误的映射系统冲突 我无法看到并修正错误。它以前一直在工作,我解开了文件,希望它能再次工作,但它没有 Object.cppC++ 未解析的外部符号“;“类”;,c++,class,lnk2001,C++,Class,Lnk2001,错误 LNK2001未解析外部符号“类对象” 当类被声明为外部时,它将为连接到它的每段代码创建此链接器错误。但当我在其他文件中创建该类的私有版本时,它们工作正常 更改类变量的名称无效,因此不会与导致错误的映射系统冲突 我无法看到并修正错误。它以前一直在工作,我解开了文件,希望它能再次工作,但它没有 Object.cpp #include "object.h" #include "Ball.h" // Constructor Object::Object() { std::map&l
#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;
}
#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;
}
ball.h
#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;
#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);
\ifndef BALL\u H
#定义球
#恩迪夫
#包括
#包括
#包括
#包括“renderer.h”
#包括“resource.h”
#包括“object.h”
空心球(位图bm、内部装配、内部装配);
无效渲染(HDC HDC、RECT*prc、位图bm);
添加
到文件Object.cpp的末尾,
对象对象的定义在哪里?对象是构造函数中的局部变量。您无法在析构函数中清除它。请查看您的头文件的“包含防护装置”——它们什么都不做。#endif应该移到文件的末尾,以防止它所包含的代码被多次包含。谢谢,我是个白痴,尽管我不记得以前放过它。下次我会记得:)
Object objects; // construct an instance of the class