derived clases in different files c++ -


how make main class in file_x.h, , file_x.cpp , derived class class made in file_x, in file_y.h , file_y.cpp

i have tried lots of things without results, please give me example both classes constructor function, variable, , regular function in both classes?

i have in window.h (main class header):

#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;  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*);         ~bwindow();         string get_name(); }; #endif /* window_h_ */ 

this in window.cpp (main class file):

#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;  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 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 , m.x < x + up_bar->w;     bool condition2 = m.y > y , m.y < y + up_bar->h;     bool condition3 = m.left;     if (condition1 , condition2){         if (condition3 , pressed == false){             pressed = true;             sx = m.x - x;             sy = m.y - y;         }else if (not(condition3)){             pressed = false;         }     }     if (condition3 , pressed == true){         x =   (m.x - sx) ;         y =   (m.y - sy) ;     } }  string bwindow::get_name(){     return name; }  bwindow::~bwindow(){  } 

this in window_types.h (derived class header):

#ifndef window_types_h_ #define window_types_h_  #include <string> #include <vector> #include "window.h"  using namespace std;  namespace windows{     class message_window : public bwindow{         private:             vector <string> message;             string title;         public:             message_window();             void start(string,vector<string>,int);             void test();     }; }  #endif /* window_types_h_ */ 

and in window_types.cpp (where error "no matching function call ‘bwindow::bwindow()"):

#include <string> #include <vector>  #include "../../utils/utilsf.h"  #include "window_types.h"   using namespace std; //here error windows::message_window::message_window(){  } 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); } void windows::message_window::test(){  } 

your #includes fine. however, you're not initializing object instances correctly. have initialize base class in constructor of derived class - , else! moreover, can't call base constructor in body of derived constructor. c++ uses special construct called 'initialization list' that. it's denoted semicolon after parameters , prior body of constructor. see what colon following c++ constructor name do? more details.

since didn't initialize bwindow in constructor of message_window, c++ compiler inserted implicit call default constructor, i.e. bwindow::bwindow(). since no such constructor exists, compiler error.

the message_window constructor should this:

void windows::message_window::message_window(string title,                                     vector <string> content,                                     int s, int a[], int b[]) : bwindow(title, 300, 200, 100, 50, a, b),   name(title),   contents(content) {    // constructor body empty in case } 

note can't initialize aand b arrays did before. caller of message_window should have done that.

similarly bwindow constructor should use initialization list this:

bwindow::bwindow(string title,int xp,int yp,int w,int h,int a[], int b[]) : x(xp), y(yp), sx(x), sy(y), name(title), pressed(false) {     //setting masks     uint32 rmask = 0x00000000;     uint32 gmask = 0x00000000;     uint32 bmask = 0x00000000;     uint32 amask = 0x00000000;      //rest of of code omitted } 

sidenote: should declare destructors virtual.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -