Thread: error allocating compiler reports pure virtual function

  1. #1
    Registered User
    Join Date
    Jul 2003

    Question error allocating compiler reports pure virtual function

    in main I have

    Menu *ptrBaseMenu = new MainMenu(library);

    but this gives me the following error:
    ain.cpp: In function `int main(int, char**)':

    main.cpp:37: cannot allocate an object of type `MainMenu'
    main.cpp:37: because the following virtual functions are abstract:
    menu.h:12: virtual void Menu::process_option(int) const

    but its not abstract here is my header file with the ovriden function from a pure virtual function of the abstract class menu
    #ifndef MAINMENU_H
    #define MAINMENU_H
    #include <map>
    using std::map;
    #include "book.h"
    #include "menu.h"
    class MainMenu:public Menu{
            MainMenu(map<string,Book> &);
            virtual void display_menu() const;
            virtual bool validate_option(int) const;
            virtual void process_option(int);
            void display_library(map<string,Book> *);   
            map<string,Book> *ptrLibrary;

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    virtual void process_option(int);
    virtual void process_option(int) const;

    are probably not being recognized as the same functions, so if you want to override the baseclass's
    'virtual void process_option(int) const', you need to prototype it as

    virtual void process_option(int) const;

    in the derived class.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. What is a virtual function pointer?
    By ting in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 02:36 AM
  3. errors initializing D3D
    By Vacation Guy in forum C++ Programming
    Replies: 3
    Last Post: 08-07-2005, 12:20 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. virtual or pure virtual
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-01-2001, 07:19 PM