The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Creating a map of Mix_Music?
Plazmotech


Joined: 21 Aug 2013
Posts: 9
I need to create a map of Mix Music with integers to play certain clips when needed. Here's what I have

AudioHandler.cpp
Code:
#ifndef __RunnyMan__AudioHandler__
#define __RunnyMan__AudioHandler__

#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2_mixer/SDL_mixer.h>
#include <map>

class AudioHandler {
private:
    std::map<int, Mix_Music* > clips;
public:
    bool init();
    bool addClip(const char *, int);
};

#endif /* defined(__RunnyMan__AudioHandler__) */


AudioHandler.h
Code:
#include "AudioHandler.h"

bool AudioHandler::init(){
    if (Mix_OpenAudio(22050, AUDIO_S16, 2, 4096) != 0){
        return 1;
    };
   
    return 0;
};

bool AudioHandler::addClip(const char * filename, int index){
    Mix_Music * music = nullptr;
    music = Mix_LoadMUS(filename);
    clips[index] = music;
   
    return true;
};


However, I keep getting

Code:
No viable overloaded '='


Why?[/code][/quote]
Creating a map of Mix_Music?
Jonas Kulla
Guest

2014-04-14 0:38 GMT+02:00 Plazmotech:
Quote:
I need to create a map of Mix Music with integers to play certain clips when needed. Here's what I have

AudioHandler.cpp



Code:

#ifndef __RunnyMan__AudioHandler__
#define __RunnyMan__AudioHandler__

#include
#include
#include
#include

class AudioHandler {
private:
    std::map clips;
public:
    bool init();
    bool addClip(const char *, int);
};

#endif /* defined(__RunnyMan__AudioHandler__) */





AudioHandler.h



Code:

#include "AudioHandler.h"

bool AudioHandler::init(){
    if (Mix_OpenAudio(22050, AUDIO_S16, 2, 4096) != 0){
        return 1;
    };
   
    return 0;
};

bool AudioHandler::addClip(const char * filename, int index){
    Mix_Music * music = nullptr;
    music = Mix_LoadMUS(filename);
    clips[index] = music;
   
    return true;
};




However, I keep getting




Code:

No viable overloaded '='




Why?[/code]



[/quote]

Shouldn't that be std::map<int, Mix_Music*>; ? I can't see the template args in your code. 
mr_tawan


Joined: 13 Jan 2014
Posts: 161
Code looks good to me. What's your compiler ?
Plazmotech


Joined: 21 Aug 2013
Posts: 9
mr_tawan wrote:
Code looks good to me. What's your compiler ?


I'm using XCode 4
Creating a map of Mix_Music?
Juan Manuel Borges Caño
Guest

That's not how you use a templated type.

Quote:

std::map <key_type, data_type, [comparison_function]>

Quote:

std::map <string, char> grade_list;

Quote:

grade_list["John"] = 'B';



More for instance, on: http://www.cprogramming.com/tutorial/stl/stlmap.html




On Tue, Apr 15, 2014 at 1:58 AM, Plazmotech wrote:
Quote:



mr_tawan wrote:

Code looks good to me. What's your compiler ?




I'm using XCode 4


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org