cannot call mem....

hi everyone

i was trying to make a func that will help programmer to lessener work

here i declare it in my MCLoad.h header
bool Load(SDL_Surface* name, std::string file);

and here
1
2
3
4
5
6
bool MCLoad::Load(SDL_Surface* name, std::string file){
    name = SDL_LoadBMP(file.c_str());
    if(name == NULL) return false;

    return true;
}


and in my main func
1
2
3
4
5
6
7
int main ( int argc, char** argv )
{
    char b;
    MCLoad::Load(b, "bg.bmp");

    return 0;
}

and the compilr gives me the error
error: cannot call member function 'bool MCLoad::Load(SDL_Surface*, std::string)' without object
pls help me
Last edited on
From the error message, it sounds as though MCLoad is a class, and Load is a method of that class. If you want to call Load, you have two choices:

1) Instantiate an object of type MCLoad, and call Load on that object

2) If the Load method doesn't in any way access the state of the MCLoad object, you can make it a static method (i.e. a class method), and call it the way you're already calling it.
thx MikeyBoy i made it static and it helped a bit but i still have probs :(

now
1
2
char b;
MCLoad::Load(b, "bg.bmp");

it gives me error: invalid conversion from 'char' to 'SDL_Surface*' [-fpermissive]

and if i delete char b;
it says error: 'b' was not declared in this scope and i declared it in func itself as Load(SDL_Surface* name, as you see
what should i do??

EDIT: maybe function Load() itself is problematic
Last edited on
Your function require the first parameter to be a SDL_Surface, and you are passing a char. Try this:
1
2
3
4
5
6
//other code
int main() {
    SDL_Surface b();
    MCLoad::Load(&b, "file.img");
    return(0);
}
Last edited on
static bool Load(SDL_Surface* name, std::string file); In the class.

MCLoad::Load(SDL_Surface* name, std::string file);Calling it.
i have fixed it with your help. thx all. and u know what, i m gonna quit keep working on it and instead i m gonna read articles and watch lessons about pointers, sdl library and some basics over again. it seems i have some gaps.

and if u wonder fixed version
static bool Load(SDL_Surface* name, std::string file);

1
2
3
4
5
6
bool MCLoad::Load(SDL_Surface* name, std::string file){
    name = SDL_LoadBMP(file.c_str());
    if(name == NULL) return false;

    return true;
}


1
2
SDL_Surface bg;
MCLoad::Load(&bg, "bg.bmp");
Last edited on
i m gonna quit keep working
Don't. Review the basics and work on it later :)
yes thats what i m gonna do. i just quit for a while. like a few days maybe.
Last edited on
Topic archived. No new replies allowed.