Problem with Allegro 4 and C ++

1

I'm trying to create a game in Allegro 4 , however I'm having problems with a method, more specifically with a BITMAP attribute. The program compiles but stops working soon after. Follow the code:

#ifndef INSTANCE_H
#define INSTANCE_H

#include "global.h"

class Instance{
public:
    Instance(bool random);
    void setTexture(string local);
    int getPositionX();
    int getPositionY();
    void drawOnBuffer(BITMAP *buff);
private:
    int x;
    int y;
    BITMAP *texture;
};

#endif

When calling the setTexture method, the program stops working. I believe the problem is occurring because the texture attribute is a pointer, but I am a beginner in object orientation and I have not yet been able to solve it. The implementation I made was as follows:

void Instance::setTexture(string local){
    texture = load_bitmap(&local[0], NULL);
}

In main, I create the object and pass the name of arquivo bitmap to be opened:

Instance pokeball(true);
pokeball.setTexture("pokeball.bmp");

Remembering that the problem is when you assign a value to the texture attribute. Whenever I remove it from the code, everything works normally.

    
asked by anonymous 07.06.2015 / 13:41

1 answer

1

See if it's not this:

void Instance::setTexture(string local){ texture = load_bitmap(local.c_str(), NULL); }

So you pass std::string "translated" to const char *

    
07.06.2015 / 17:20