最近Visual StudioをインストールしてSFMLライブラリとBoostライブラリで少し作業を開始しましたが、この奇妙な静的クラスのヘッダーファイルで静的void関数を宣言しているときに、関数内にBOOST_FOREACHコードが存在する場合にのみ、「findTextures 'の関数定義が見つかりません」とVisual Studioから通知されます。なぜあなたはこのことが起こるのか知っていますか?本当にありがとう。Visual Studio C++とBoost Lib:BOOST_FOREACHが存在するときにのみ関数定義が見つかりません
これはTextureLoader.h次のようになります。
#include <SFML/Graphics.hpp>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <iostream>
class TextureLoader {
public:
static const sf::Texture& getTexture(sf::String l_name);
static void findTextures();
private:
static std::map<sf::String, sf::Texture> textures;
};
そして、これはTextureLoader.cppクラスです:
#include "TextureLoader.h"
// Get texture using name
const sf::Texture& TextureLoader::getTexture(sf::String l_name) {
return textures.at(l_name);
}
void TextureLoader::findTextures() {
namespace fs = boost::filesystem;
fs::path targetDir("/Textures");
fs::directory_iterator it(targetDir), eod;
BOOST_FOREACH(fs::path const &p, std::make_pair(it, eod)) {
if(fs::is_regular_file(p)) {
std::cout << p.filename();
}
}
}
出力:
1>------ Build started: Project: MasterTest, Configuration: Debug Win32 ------
1>TextureLoader.cpp
1>Unknown compiler version - please run the configure tests and report the results
1>TextureLoader.obj : error LNK2001: unresolved external symbol "private: static class std::map<class sf::String,class sf::Texture,struct std::less<class sf::String>,class std::allocator<struct std::pair<class sf::String const ,class sf::Texture> > > TextureLoader::textures" ([email protected]@@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected][email protected][email protected]@@[email protected]@@[email protected]@@[email protected]@[email protected]@A)
1>F:\Coding\VSProjects\MasterTest\Debug\MasterTest.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "MasterTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Visual Studioの* exact *と* complete *出力がなければ、私たちは本当に助けにはなりません。誰かがあなたを助けることができるようにするには、エラーメッセージ(*出力*ウィンドウから*エラーではない!)を引用することが不可欠です。 –
@JanHudecさんが質問を編集してエラーログを追加しました:) – Crack498
** OUTPUT **ウィンドウから** TEXT **としてください。 –