You mean like this?
Code:
#include <iostream>
#include <vector>
class A {
public:
virtual void bla() = 0;
friend std::ostream& operator << ( std::ostream& s, const A& p ) {
s << p.a;
return s;
}
int a;
};
class B : public A{
public:
B() : array(new A[5]) {}
virtual void bla() { std::cout << "I am bla\n" << std::endl; }
private:
A *array;
};
int main()
{
B b();
return 0;
}
Same error as my approach
Code:
samaras@samaras-A15:~$ g++ -Wall px.cpp -o px
px.cpp: In constructor ‘B::B()’:
px.cpp:16:28: error: cannot allocate an object of abstract type ‘A’
px.cpp:4:7: note: because the following virtual functions are pure within ‘A’:
px.cpp:6:22: note: virtual void A::bla()
a and b are left-overs from another example. I discarded them.
>Also are you sure you want to have an array of A in your B class?
>If so why do you have the inheritance?
I guess so, since I need an array, which will be of type of a base (abstract) class. Then there are two classes that inherit from this base. I want to cast depending on what I have in the .cpp. I do not feel like changing that now.
>What do you mean by "N has to be taken from input"?
I mean that N is not a constant as I thought in the start. Now, N is provided by the input. by the user.