У меня есть следующие три файла, из которого я не могу найти источник ошибки, что она производит:C++ SFML Gamedev Book - неразрешенный внешний символ из ResourceHolder класса
main.cpp
#include <SFML/Graphics.hpp>
#include <iostream>
#include "ResourceHolder.h"
namespace Textures
{
enum ID { Landscape, Airplane, Missile };
}
int main()
{
//...
try
{
ResourceHolder<sf::Texture, Textures::ID> textures;
textures.load(Textures::Airplane, "Airplane.png");
}
catch (std::runtime_error& e)
{
std::cout << "Exception: " << e.what() << std::endl;
}
//...
}
ResourceHolder.h
#pragma once
#include <map>
#include <string>
#include <memory>
#include <stdexcept>
#include <cassert>
template <typename Resource, typename Identifier>
class ResourceHolder
{
public:
void load(Identifier id, const std::string& fileName);
Resource& get(Identifier id);
const Resource& get(Identifier id) const;
private:
void insertResource(Identifier id, std::unique_ptr<Resource> resource);
std::map<Identifier, std::unique_ptr<Resource>> mResourceMap;
};
ResourceHolder.cpp
#include "ResourceHolder.h"
template <typename Resource, typename Identifier>
void ResourceHolder<Resource, Identifier>::load(Identifier id, const std::string& fileName)
{
//Create and load resource
std::unique_ptr<Resource> resource(new Resource());
if (!resource->loadFromFile(fileName)) {
throw std::runtime_error("ResourceHolder::load - Failed to load " + fileName);
}
//If loading was successful, insert resource to map
insertResource(id, std::move(resource));
}
template <typename Resource, typename Identifier>
Resource& ResourceHolder<Resource, Identifier>::get(Identifier id)
{
auto found = mResourcemap.find(id);
assert(found != mResourceMap.end());
return *found->second();
}
template <typename Resource, typename Identifier>
void ResourceHolder<Resource, Identifier>::insertResource(Identifier id, std::unique_ptr<Resource> resource)
{
//Insert and check success
auto inserted = mResourceMap.insert(std::make_pair(id, std::move(resource)));
assert(inserted.second);
}
Если бы я, чтобы удалить комбинацию примерки поймать в main.cpp, код компилируется нормально; Однако, если я оставлю его там, он дает мне ошибку LNK2019 (неразрешенный внешний символ).
Какова причина этой ошибки и как ее исправить?
Ошибка: LNK2019: неразрешенный внешний символ "public: void __thiscall ResourceHolder :: load (enum Textures :: ID, class std :: basic_string < char, struct std :: char_traits , класс std :: allocator > const &) "(? load @?$ ResourceHolder @ VTexture @ SF @@ W4ID @ текстуры @@@@ QAEXW4ID @ текстуры @@ ABV? $ Basic_string @ DU? $ Char_traits @ D @ станд @@ V? $ Распределитель @ D @ 2 @@ станд @@@ Z), на которые ссылается функция _main –
random5999