Thread: derived classes

  1. #1
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272

    derived classes

    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    class Stack {
          public:
                 class Underflow { };
                 class Overflow { };
                 class Bad_Size { };
                 
                 virtual void push(char c) = 0;
                 virtual char pop() = 0;
    };
    
    class Array_stack : public Stack {
          char *p;
          int max_size;
          int top;
          public:
                 Array_stack(int s); 
                 ~Array_stack();
                 
                 void push(char c);
                 char pop();
    };
    
    Array_stack::Array_stack(int s) //cant compile
    {
                if(s > 10000)
                     throw Bad_Size();
                p = new char[s];
                max_size = s;
                top = 0;                      
    }
    int main()
    {
         
          
          
    }
    Why wont this work?

    How can i define a constructor that's declared inside a derived class, but i want to define it outside of the class itself?
    Last edited by Tool; 06-14-2010 at 09:17 AM.

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    What is the compile error?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272
    Oh nvm. The problem is i didnt define the push/pop functions.

    Seems like you cant just define the constructor, if you define the constructor you have to define all of the functions in the class aswell.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. storing derived classes in a stl container
    By *DEAD* in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2008, 07:50 PM
  2. Deleting derived classes
    By *DEAD* in forum C++ Programming
    Replies: 6
    Last Post: 09-30-2008, 12:37 PM
  3. Help accessing classes and derived classes
    By hobbes67 in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2005, 02:46 PM
  4. Replies: 8
    Last Post: 07-27-2003, 01:52 PM
  5. Inheiritance and derived classes
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2001, 03:50 PM