-
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?
-
What is the compile error?
-
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.