Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Schulterblatt

Pages: [1]
1
Audio / Re: Why is sf::Music non-copyable?
« on: April 29, 2015, 10:00:16 pm »
Quote
You cannot use the stack for a dynamically sized container.
Sorry, I meant the heap.

Quote
Those will be supported when SFML switches to C++11.
I didn't know that it hadn't. Come to think of it, that would explain the lack of rvalue references.

Well, thank you for the explanation!

2
Audio / Why is sf::Music non-copyable?
« on: April 29, 2015, 07:35:49 pm »
class MusicManager
{
private:
        std::vector<sf::Music> music;
        int iCrt;

public:
        void Add(const std::string& s)
        {
                sf::Music m;
                if (!m.openFromFile(s)) return;
                music.push_back(std::move(m));
        }

        void SetCurrent(int index)
        { iCrt = index; }

        sf::Music& GetCurrent()
        { return music[iCrt]; }
};

int main()
{
        MusicManager mm;
        mm.Add("content/audio/music/Caught.wav");
        mm.SetCurrent(0);
        mm.GetCurrent().play();

        getchar();
}
 

Since sf::Music inherits from sf::NonCopyable, this code will not run, giving me the error message error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable' using Visual C++ 12.

Why is sf::Music non-copyable? Neither sf::Sound nor sf::SoundBuffer has this restriction.

The only way I've found to fix this is to use an array of sf::Music* and create each one on the stack individually.

(Sorry if this has already been explained elsewhere, but I couldn't find it anywhere in SFML's documentation.)

Pages: [1]