Can't access a vector inside a class

closed account (Sy0XoG1T)
Alright I'm trying to use a vector inside of a class but I'm getting unresolved externals and I'm not sure on how to fix it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Sfx
{
private:
	RenderWindow & renderwindow;
	vector<SoundBuffer> File;

public:
	Sfx(RenderWindow & Screen): renderwindow(Screen){}
	void LoadSfxFile(std::string filename);
};

void Sfx::LoadSfxFile(std::string filename)
{
	File.at(File.size()-1).LoadFromFile(filename);
}


Getting errors from trying to access File in LoadSfxFile.
Can you post the error message?
closed account (Sy0XoG1T)
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::SoundBuffer::LoadFromFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?LoadFromFile@SoundBuffer@sf@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: void __thiscall Sfx::LoadSfxFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadSfxFile@Sfx@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) main.obj

Error 2 fatal error LNK1120: 1 unresolved externals
closed account (Sy0XoG1T)
Wait I think it's a problem with SFML's SoundBuffer class. int works perfectly fine in the same situation.
The problem has nothing to do with vector.

The linker can't find the LoadFromFile function. Are you linking to the necessary libraries?

Also, this is unrelated, but:

1
2
3
File.at(File.size()-1).LoadFromFile(filename);  // instead of this

File.back().LoadFromFile(filename); // you can do this 

Topic archived. No new replies allowed.