3 Replies - 530 Views - Last Post: 28 May 2011 - 04:43 PM Rate Topic: -----

#1 coolguy_193  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 24-April 11

making object of derived class

Posted 27 May 2011 - 10:43 PM

I cant make object of the derived class and the base class contains pure virtual functions...why is this so??

#include <allegro.h>
void mouse();
class initialization
      {
      public:
             void init()
                  {
                        allegro_init();
                        set_color_depth(32);
	                    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	                    install_timer();
                        install_keyboard();
	                    install_mouse();
                  }              
      };
                    
class base
      {
        public:     
               virtual void make_buffer() = 0;
               virtual void make_sprite_to_buffer() = 0;
               virtual void make_buffer_to_screen() = 0;
      };
      
class back_g : public base
      {
            private:
                    BITMAP* back_ground;
                    BITMAP* buffer;
                    int x, y;
                                        
            public:
                   back_g(int a, int B)/>
                         {
                                x = a;
                                y = b;
                         }
                   void make_buffer()
                        {
                                     buffer = create_bitmap(640, 480);
                        }
                   void make_sprite_to_buffer()
                        {
                               back_ground = load_bitmap("res/background/back2.bmp", NULL);                                     
                               blit(back_ground, buffer, 0, 0, x, y, 640, 480);
                        }
                   void make_buffer_to_screen()
                        {
                                               blit(buffer, screen, 0, 0, x, y, 640, 480);
                        }
                   ~back_g()
                          {
                               destroy_bitmap(back_ground);
                               destroy_bitmap(buffer);
                          }
       };
                    
                    
int main()
{
       initialization in;
       back_g b(0, 15);
       
       
       
       
       in.init();
       
       
       
       readkey();
    
    
    
return 0;
}
END_OF_MAIN()


void mouse()
     {
            BITMAP* mouse_pointer = NULL;
             mouse_pointer = load_bitmap("res/pointer.bmp", NULL);
             set_mouse_sprite(mouse_pointer);
             show_mouse(screen); 
     }




Is This A Good Question/Topic? 0
  • +

Replies To: making object of derived class

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,663
  • Joined: 23-August 08

Re: making object of derived class

Posted 28 May 2011 - 03:05 AM

Moved to C and C++. C++ Programmers forum is not for help, it's for discussion.
Was This Post Helpful? 0
  • +
  • -

#3 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 687
  • View blog
  • Posts: 2,377
  • Joined: 31-December 10

Re: making object of derived class

Posted 28 May 2011 - 01:32 PM

Why do you need to use inheritance? I'm not familiar with allegro, but it might help if you posted whatever errors you're getting, or what you expect to happen and what actually happened if you were able to compile and run it.
Was This Post Helpful? 0
  • +
  • -

#4 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1623
  • View blog
  • Posts: 5,710
  • Joined: 03-August 09

Re: making object of derived class

Posted 28 May 2011 - 04:43 PM

well im not exactly sure what your asking but you declared 3 pure virtual functions one lines 20-22 and it appears that you implemented those in your base class.

as vividexstance asked, why do you need to use inheritance? your base class is pointless unless you make another class the implements the pure virtual functions differently.

This post has been edited by ishkabible: 28 May 2011 - 05:14 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1