C++
I have been working hard on learning Inheritance
and Polymorphism
for weeks. I can have Mammals with Dogs and Cats, O can derive Puppy's from Dogs and what not. I have a NaughtleNum base class
with a + operator
And the derived class
is Naughty1. (Sorry, but I hate Foo Bar)
Here is the Code:
#include <iostream>
#include <math.h>
using namespace std;
typedef unsigned char UCHAR;
typedef unsigned short int SHORT;
class NaughtleNum;
class Naughty1;
class NaughtleNum {
public:
NaughtleNum() {
cout << "Hello NaughtleNum 1\n";
}; //constructors
virtual~NaughtleNum() {
cout << "Bye Bye NaughtleNum\n";
}; //destructor
virtual NaughtleNum * operator + (NaughtleNum * ) = 0;
};
class Naughty1: public NaughtleNum {
public:
Naughty1() {
cout << "Hello Naughty1\n";
value = 3;
}; //constructors
~Naughty1() {
cout << "Bye Bye Naughty1\n";
}; //destructor
Naughty1 * operator + (Naughty1 * ) {}
private:
UCHAR value;
};
int main() {
cout << "I am Here\n";
NaughtleNum * N1;
N1 = new Naughty1;
return 0;
}
I want to have a + operator
for two Naughty Numbers!
Messages are:
daddio@LittleBeast:~/Programs/MyLib/Naughty> g++ -g -o NaughtleNum NaughtleNum.cpp
NaughtleNum.cpp: In function ‘int main()’:
NaughtleNum.cpp:35:12: error: cannot allocate an object of abstract type ‘Naughty1’
N1=new Naughty1;
^
NaughtleNum.cpp:19:7: note: because the following virtual functions are pure within ‘Naughty1’:
class Naughty1: public NaughtleNum
^
NaughtleNum.cpp:16:30: note: virtual NaughtleNum* NaughtleNum::operator+(NaughtleNum*)
virtual NaughtleNum* operator + (NaughtleNum*) =0;
^
daddio@LittleBeast:~/Programs/MyLib/Naughty>
What am I missing here?