I have the usual unresolved external symbol problem
LNK2019 unresolved external symbol "public: void __thiscall
Aldo::AssetManager::LoadTexture(class std::basic_string<char,struct std::char_traits<char>,
class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)"
(?LoadTexture@AssetManager@Aldo@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z)
referenced in function "public: virtual void __thiscall Aldo::SplashState::Init(void)"
(?Init@SplashState@Aldo@@UAEXXZ)
SFML template C:\Users\ajb266\Documents\Aldo\SFML template\SFML template\SplashState.obj 1
It seems the issue is LoadTexture is not defined, but then I have defined the LoadTexture constructor in AssetManager's cpp file. It seems SplashState could also be involved. From what I understand, the object file SplashState is created after compilation of SplashState.cpp, and then linked with the libraries using a linker. Maybe I am missing something with the linker settings in Visual Studio?
My relevant files are as follows:
AssetManager.hpp:
#pragma once
#include <map>
#include <SFML/Graphics.hpp>
namespace Aldo
{
class AssetManager {
public:
AssetManager() {}
~AssetManager() {}
void LoadTexture(std::string name, std::string fileName);
sf::Texture &GetTexture(std::string name);
void LoadFont(std::string name, std::string fileName);
sf::Font &GetFont(std::string name);
private:
std::map<std::string, sf::Texture> _textures;
std::map<std::string, sf::Font> _fonts;
};
}
AssetManager.cpp:
#include "AssetManager.hpp"
namespace Aldo {
void AssetManager::LoadTexture(std::string name, std::
string fileName) {
sf::Texture tex;
if (tex.loadFromFile(fileName)) {
this->_textures[name] = tex;
}
}
sf::Texture& AssetManager::GetTexture(std::string name) {
return this->_textures.at(name);
}
void AssetManager::LoadFont(std::string name, std::string fileName) {
sf::Font font;
if (font.loadFromFile(fileName)) {
this->_fonts[name] = font;
}
}
sf::Font& AssetManager::GetFont(std::string name) {
return this->_fonts.at(name);
}
}
SplashState.hpp:
#pragma once
#include <SFML/Graphics.hpp>
#include "state.hpp"
#include "GameLoop.hpp"
namespace Aldo {
class SplashState : public State
{
public:
SplashState(GameDataRef data);
void Init();
void HandleInput();
void Update(float dt);
void Draw(float dt);
private:
GameDataRef _data;
sf::Clock _clock;
sf::Texture _backgroundTexture;
sf::Sprite _background;
};
}
SplashState.cpp:
#include <sstream>
#include "SplashState.hpp"
#include "DEFINITIONS.hpp"
#include <iostream>
namespace Aldo
{
SplashState::SplashState(GameDataRef data) : _data(data)
{
}
void SplashState::Init() {
_data->assets.LoadTexture("Splash State Background",
SPLASH_SCENE_BACKGROUND_FILEPATH);
_background.setTexture(this->_data->assets.GetTexture("Splash State Background"));
}
void SplashState::HandleInput() {/*only handle and check whether the X button to close the window is pressed or not*/
sf::Event event;
while (_data->window.pollEvent(event))
{
if (sf::Event::Closed == event.type) {
_data->window.close();
}
}
}
void SplashState::Update(float dt) {
if (_clock.getElapsedTime().asSeconds() > SPLASH_STATE_SHOW_TIME) {
std::cout << "go to main menu" << std::endl;
}
}
void SplashState::Draw(float dt) {
_data->window.clear();
_data->window.draw(_background);
_data->window.display();
}
}
I'm using Visual Studio and c++17. I'm new to C++ so forgive me if this is too trivial.