我刚开始使用Lazy Foo教程在C ++中使用SDL进行编程,而且我对目标编程并不熟悉。我已经开始收到LNK2019错误,但找不到它的原因。
我有一个类LTexture:
#pragma once
#include<string>
#include<SDL.h>
#include<SDL_image.h>
class LTexture
{
public:
LTexture();
~LTexture();
//Loads image at specified path
bool loadFromFile(std::string path, SDL_Renderer* _gameRenderer);
void free();
//Renders texture at given point
void render(int x, int y, SDL_Renderer* _gameRenderer);
int getWidth();
int getHeight();
private:
//The actual hardware texture
SDL_Texture* _texture;
//Image dimensions
int _width;
int _height;
};
#pragma once
#include<string>
#include<SDL.h>
#include<SDL_image.h>
class LTexture
{
public:
LTexture();
~LTexture();
//Loads image at specified path
bool loadFromFile(std::string path, SDL_Renderer* _gameRenderer);
void free();
//Renders texture at given point
void render(int x, int y, SDL_Renderer* _gameRenderer);
int getWidth();
int getHeight();
private:
//The actual hardware texture
SDL_Texture* _texture;
//Image dimensions
int _width;
int _height;
};
一个AssetLoader类:
#pragma once
#include <stdio.h>
#include<iostream>
#include "LTexture.hpp"
class AssetLoader
{
public:
//Loads media
bool loadMedia(SDL_Renderer* _gameRenderer);
//Loads individual image as texture
SDL_Texture* loadTexture(std::string path, SDL_Renderer* _gameRenderer);
//Scene textures
LTexture gFooTexture;
LTexture gBackgroundTexture;
};
我得到的错误: 严重性代码描述项目文件行抑制状态 错误LNK2019未解析的外部符号“public:bool __thiscall LTexture :: loadFromFile(class std :: basic_string,class std :: allocator&gt;,struct SDL_Renderer *)”(?loadFromFile @ LTexture @@ QAE_NV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ PAUSDL_Renderer @@@ Z)在函数“public:bool __thiscall AssetLoader :: loadMedia(struct SDL_Renderer *)”中引用(?loadMedia @ AssetLoader @@ QAE_NPAUSDL_Renderer @@@ Z)
严重级代码描述项目文件行抑制状态 错误LNK2019未解析的外部符号“public:__thiscall LTexture :: LTexture(void)”(?? 0LTexture @@ QAE @ XZ)在函数“public:__thiscall AssetLoader :: AssetLoader(void)”中引用(?? 0AssetLoader @@ QAE @ XZ)
严重级代码描述项目文件行抑制状态 错误LNK2019未解析的外部符号“public:__thiscall LTexture :: ~LTexture(void)”(?? 1LTexture @@ QAE @ XZ)在函数__unwindfunclet中引用$ ?? 0AssetLoader @@ QAE @XZ $ 0
当它试图在AssetLoader :: loadMedia函数中调用LTexture :: loadFromFile函数时显然失败,如下所示:
#pragma once
#include <stdio.h>
#include<iostream>
#include "LTexture.hpp"
class AssetLoader
{
public:
//Loads media
bool loadMedia(SDL_Renderer* _gameRenderer);
//Loads individual image as texture
SDL_Texture* loadTexture(std::string path, SDL_Renderer* _gameRenderer);
//Scene textures
LTexture gFooTexture;
LTexture gBackgroundTexture;
};
LTexture :: loadFromFile的实现是这样的:
#pragma once
#include"AssetLoader.hpp"
#include"LTexture.hpp"
bool AssetLoader::loadMedia(SDL_Renderer* _gameRenderer)
{
//Loading success flag
bool _success = true;
//Load splash image
if (!gFooTexture.loadFromFile("foo.png", _gameRenderer))
{
printf("Failed to load Foo texture image!\n");
_success = false;
}
//Load background texture
if (!gBackgroundTexture.loadFromFile("background.png", _gameRenderer))
{
printf("Failed to load background texture image!\n");
_success = false;
}
return _success;
}
#pragma once
#include"AssetLoader.hpp"
#include"LTexture.hpp"
bool AssetLoader::loadMedia(SDL_Renderer* _gameRenderer)
{
//Loading success flag
bool _success = true;
//Load splash image
if (!gFooTexture.loadFromFile("foo.png", _gameRenderer))
{
printf("Failed to load Foo texture image!\n");
_success = false;
}
//Load background texture
if (!gBackgroundTexture.loadFromFile("background.png", _gameRenderer))
{
printf("Failed to load background texture image!\n");
_success = false;
}
return _success;
}
请帮助,我真的无处可问。