class - objects not working in SDL (C++) -


i working on simple game in c++, sdl api. put image bliting functions in class on separate document less messy on main file. however, when try call functions using object class, ide says making undefined reference functions. here main file:

#include "sdl/sdl.h" #include "sdl/sdl_image.h" #include "sdl/sdl_ttf.h" #include "imageblitingfunctions.h" #include <iostream> #include <string> #include <sstream>  int screenw = 640; int screenh = 480; int screenbpp = 32;  sdl_surface* window = sdl_setvideomode(screenw, screenh, screenbpp, sdl_swsurface);  imageblitingfunctions ibfobject;  sdl_surface* background1; sdl_surface* player1;  int main(int argc, char* args[]) {     sdl_init(sdl_init_everything);     ttf_init();      background1 = ibfobject.loadimg("background.png");     player1 = ibfobject.loadimg("swordtest.png");      ibfobject.blitimg(0, 0, window, background1, 0, 0, 1000, 1000);     ibfobject.blitimg(0, 0, window, player1, 100, 0, 100, 300);      sdl_freesurface(background1);     sdl_freesurface(player1);      sdl_quit();      return 0; } 

here header class:

#include "sdl/sdl.h" #include "sdl/sdl_image.h" #include "sdl/sdl_ttf.h" #include <iostream> #include <string> #ifndef imageblitingfunctions_h #define imageblitingfunctions_h   class imageblitingfunctions {     public:         sdl_surface *loadimg(std::string filename);          void blitimg(int px, int py, sdl_surface *window, sdl_surface *image, int cpx, int cpy, int cph, int cpw);          sdl_surface *loadtext(int red, int blue, int green, std::string fontname, int fontsize, std::string text); };  #endif // imageblitingfunctions_h 

and here class:

#include "imageblitingfunctions.h" #include "sdl/sdl.h" #include "sdl/sdl_image.h" #include "sdl/sdl_ttf.h" #include <iostream> #include <string>  sdl_surface* imageblitingfunctions::loadimg(std::string filename) {     sdl_surface *img = img_load(filename.c_str());      sdl_surface *imgopt = sdl_displayformat(img);      sdl_freesurface(img);      return imgopt; }  void imageblitingfunctions::blitimg(int px, int py, sdl_surface *window, sdl_surface *image, int cpx, int cpy, int cph, int cpw) {     sdl_rect positionimg;     positionimg.x = px;     positionimg.y = py;      sdl_rect clipp;     clipp.x = cpx;     clipp.y = cpy;     clipp.h = cph;     clipp.w = cpw;      sdl_blitsurface(image, &clipp, window, &positionimg);      sdl_flip(window); }  sdl_surface* imageblitingfunctions::loadtext(int red, int blue, int green, std::string fontname, int fontsize, std::string text) {     int color1 = red;     int color2 = blue;     int color3 = green;      sdl_color textcolor = {color1, color2, color3};      ttf_font *font1 = ttf_openfont(fontname.c_str(), fontsize);      sdl_surface *message1 = ttf_rendertext_solid(font1, text.c_str(), textcolor);      return message1; } 

any appreciated.

an undefined reference function means linker can't find function definition. definition of function you've put in code "and here class:" (maybe call imageblitingfunctions.cpp or similar?) problem you're ide can't find file.

to solve problem need fix project configuration.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -