Well I am getting an error since I added virtual functions that I have no idea about it. Do you?
There are three errors in total:
Here the error code files:
window.h
#ifndef WINDOW_H_
#define WINDOW_H_
#include <string>
#include <vector>
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include "../../utils/event.h"
#include "../../utils/button.h"
using namespace std;
//ERROR HERE "undefined reference to `vtable for bwindow'"
class bwindow{
protected:
SDL_Surface* up_bar;
SDL_Surface* content;
SDL_Surface* to_blit;
SDL_Surface* text;
vector <button*> botns;
string name;
int x;
int y;
bool pressed;
int sx;
int sy;
public:
bwindow(string,int,int,int,int,int*,int*);
void graphic_update(SDL_Surface*);
void logic_update(events*);
virtual void pgu(SDL_Surface*);
virtual void plu(events*);
string get_name();
};
#endif /* WINDOW_H_ */
window.cpp:
#include <string>
#include <vector>
#include <iostream>
#include "SDL/SDL.h"
#include "SDL/SDL_gfxPrimitives.h"
#include "SDL/SDL_ttf.h"
#include "../../utils/SDL_functions.h"
#include "../../utils/event.h"
#include "../../extra_data/extra_data.h"
#include "window.h"
using namespace std;
//ERROR HERE "undefined reference to `vtable for bwindow'"
bwindow::bwindow(string title,int xp,int yp,int w,int h,int a[], int b[]){
//seting variables
x = xp;
y = yp;
sx = x;
sy = y;
name = title;
pressed = false;
//seting masks
Uint32 rmask = 0x00000000;
Uint32 gmask = 0x00000000;
Uint32 bmask = 0x00000000;
Uint32 amask = 0x00000000;
//creating up_bar
up_bar = SDL_CreateRGBSurface(SDL_SWSURFACE, w, 20, 32,rmask, gmask, bmask, amask);
SDL_FillRect( up_bar, &up_bar->clip_rect, SDL_MapRGB( up_bar->format, 0xFF, 0xFF, 0xFF ) );
boxRGBA(up_bar ,0, 0, w,20,a[0],a[1],a[2],a[3]);
//creating content area
content = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h-30, 32,rmask, gmask, bmask, amask);
boxRGBA(content,0, 0,w, h - 25,b[0],b[1],b[2], b[3]);
//adding borders
sdlf::add_border(up_bar,1,1,1,1,0,0,0,255);
sdlf::add_border(content,1,1,1,1,0,0,0,255);
//adding the up-text
SDL_Color textColor = { 0 , 0 ,0 };
TTF_Font *font;
font = fonts::load_john_han(15);
text = TTF_RenderText_Solid(font,title.c_str(),textColor);
apply_surface(20,5,text,up_bar);
//creating final surface
to_blit = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,rmask, gmask, bmask, amask);
}
void bwindow::graphic_update(SDL_Surface* screen){
SDL_FillRect( to_blit, &to_blit->clip_rect, SDL_MapRGB( to_blit->format, 0xFF, 0xFF, 0xFF ) );
apply_surface(0,0, up_bar, to_blit);
apply_surface(0,20,content,to_blit);
apply_surface(x,y,to_blit,screen);
}
void bwindow::logic_update(events* evs){
mouse m = evs->get_mouse();
bool condition1 = m.x > x and m.x < x + up_bar->w;
bool condition2 = m.y > y and m.y < y + up_bar->h;
bool condition3 = m.left;
if (condition1 and condition2){
if (condition3 and pressed == false){
pressed = true;
sx = m.x - x;
sy = m.y - y;
}else if (not(condition3)){
pressed = false;
}
}
if (condition3 and pressed == true){
x = (m.x - sx) ;
y = (m.y - sy) ;
}
}
string bwindow::get_name(){
return name;
}
window_types.h (No errors in this file)
/*
* window_types.h
*
* Created on: Aug 10, 2013
* Author: newtonis
*/
#ifndef WINDOW_TYPES_H_
#define WINDOW_TYPES_H_
#include <string>
#include <vector>
#include "SDL/SDL.h"
#include "SDL/SDL_gfxPrimitives.h"
#include "SDL/SDL_ttf.h"
#include "../../utils/SDL_functions.h"
#include "window.h"
#include "../../extra_data/extra_data.h"
using namespace std;
namespace windows{
class message_window : public bwindow{
private:
vector <string> message;
string title;
public:
message_window(string,string,int a[],int b[]);
void pgu(SDL_Surface* SCREEN);
void plu(events ev);
void start(string,vector<string>,int);
void test();
};
message_window* get_message_window(string,string,int);
}
#endif /* WINDOW_TYPES_H_ */
window_types.cpp (Here an error)
#include <string>
#include <vector>
#include <iostream>
#include "SDL/SDL.h"
#include "SDL/SDL_gfxPrimitives.h"
#include "SDL/SDL_ttf.h"
#include "../../utils/SDL_functions.h"
#include "../../utils/utilsf.h"
#include "../../extra_data/extra_data.h"
#include "window.h"
#include "window_types.h"
using namespace std;
namespace windows{
//ERROR HERE "vtable for windows::message_window"
message_window::message_window(string title,string con,int a[],int b[]) : bwindow(title, 300, 200, 150, 100,a,b){
vector <string> content_ordered;
string new_lines = "";
for (int x = 0;x < con.size();x++){
if (x < con.size()-1){
if (utilsf::cts(con[x]) == "/" and utilsf::cts(con[x+1]) == "r"){
content_ordered.push_back(new_lines);
new_lines = "";
x+=2;
}
}
if (utilsf::cts(con[x]) == ""){
new_lines = new_lines + " ";
}
new_lines = new_lines + utilsf::cts(con[x]);
if (x == con.size()-1){
content_ordered.push_back(new_lines);
}
}
SDL_Color textColor = {0, 0, 0};
TTF_Font *font = fonts::load_font1(15);
int h = 3;
for (int x = 0;x < content_ordered.size();x++){
SDL_Surface* text_surface = TTF_RenderText_Solid(font,content_ordered[x].c_str(),textColor);
apply_surface(5,h,text_surface,content);
h += text_surface->h + 3;
}
}
/*void windows::message_window::start(string title,vector <string> content,int s){
int yp = 200;
int xp = 300;
int w = 100;
int h = 50;
int a[4];
int b[4];
a[0] = utilsf::randrange(0,256,s);
a[1] = utilsf::randrange(0,256,s);
a[2] = 200;
a[3] = 255;
b[0] = 200;
b[1] = utilsf::randrange(0,256,s);
b[2] = utilsf::randrange(0,256,s);
b[3] = 255;
bwindow(title,xp,yp,w,h,a,b);
}*/
message_window* get_message_window(string title,string msj,int s){
int a[4];
int b[4];
a[0] = utilsf::randrange(0,256,s);
a[1] = utilsf::randrange(0,256,s);
a[2] = 200;
a[3] = 255;
b[0] = 200;
b[1] = utilsf::randrange(0,256,s);
b[2] = utilsf::randrange(0,256,s);
b[3] = 255;
message_window *w = new message_window(title,msj,a,b);
return w;
}
}
You need to implement void bwindow::pgu(SDL_Surface*)
and void bwindow::plu(events*)
, or make them pure virtual:
virtual void pgu(SDL_Surface*) = 0;
virtual void plu(events*) = 0;
With pure virtual methods, you will not be able to instantiate bwindow
objects, but can instantiate derived types, as long as the methods are implemented in those types.
See more on pure virtual methods here