Hi everybody!
I'm working on a following program:
#include "stdafx.h"
#include <iostream>
using namespace std;
class char_queue
{
protected:
struct charList
{
public:
char val;
charList* next;
charList(char ch, charList* ptr)
{
val = ch; next = ptr;
}
};
protected:
charList* begin;
charList* end;
void clearCharList();
public:
char_queue();
bool find(char ch);
virtual void add(char ch);
virtual void clear()=0;
virtual void print();
};
char_queue::char_queue()
{
begin = end = NULL;
}
void char_queue::clearCharList()
{
while(begin!=NULL)
{
char_queue::charList* current = begin->next;
delete begin;
begin=current;
}
}
bool char_queue::find(char ch)
{
char_queue::charList* current = begin;
while(current!=NULL)
{
if(current->val==ch) return true;
current = current->next;
}
return false;
}
void char_queue::add(char ch)
{
char_queue::charList* current = new char_queue::charList(ch, NULL);
if(begin == NULL) begin = end = current;
end->next = current;
end = current;
}
void char_queue::print()
{
char_queue::charList* current = begin;
while(current!=end)
{
cout<<current->val<<" ";
current=current->next;
}
cout<<current->val<<endl;
}
int main(int argc, char*argv[])
{
char_queue ob;
char myChar[5]={'H','e','l','l','o'};
for (int i=0; i<5; i++)
ob.add(myChar[i]);
ob.print();
system("PAUSE");
return 0;
}
While compiling I got an error here: char_queue ob;
The error is: Error 1 error C2259: 'char_queue' : cannot instantiate abstract class
I don't understand what is going on?
So I really need your helps.
Thanks in advanced!