SFML community forums

Help => Audio => Topic started by: Cryonic on July 24, 2015, 02:13:26 am

Title: error C2248
Post by: Cryonic on July 24, 2015, 02:13:26 am
I am getting the following error:

error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'

After I put my declaration in my class header file:
vector<sf::Music> music;

Title: Re: error C2248
Post by: G. on July 24, 2015, 02:41:09 am
sf::Music is non copyable.
std::vector makes copies of its elements.
You can make a vector of pointers (or smart pointers) to sf::Music.

http://www.gamedev.net/topic/631713-sfml-sfmusic-cannot-be-copied/#entry4982914
Title: Re: error C2248
Post by: Cryonic on July 26, 2015, 10:36:07 pm
How exactly am I supposed to word it out? I am getting an error on the "openFromFile" line.
I am hovering above it, and it says "Error: expression must have class type"

// Header file
class MyClass
{
   vector<sf::Music*> music;
        MyClass();
}

// Source file
MyClass::MyClass()
{
   for (int i = 0; i < MAX; i++)
      { music.push_back(new sf::Music()); }
   music[0].openFromFile("soundFile.ogg");
}
Title: Re: error C2248
Post by: Rosme on July 27, 2015, 02:10:59 am
It looks like you lack some basic C++ knowledge maybe? Reading a good book could help. Since your vector contains pointer, you need to use -> instead of . to access the members and functions of the sf::Music pointer.