I am programming in c++ on a linux system for class. I have a class Queue and a class Sim which inherits the public members of Queue. Queue is compiling and testing fine. However when I try to code the constructor for class Sim I get an error.
I have omitted irrelevant code.
error:
~$ make -f p04make
make: Warning: File `Sim04.cpp' has modification time 7.2 s in the future
g++ -g -c Sim04.cpp
Sim04.cpp: In constructor âSim::Sim(int)â:
Sim04.cpp:28:64: error: no matching function for call to âQueue::Queue()â
Sim04.cpp:28:64: note: candidates are: Queue04.h:27:3: note: Queue::Queue(int)
Queue04.h:27:3: note: candidate expects 1 argument, 0 provided
Queue04.h:19:7: note: Queue::Queue(const Queue&)
Queue04.h:19:7: note: candidate expects 1 argument, 0 provided
make: * [Sim04.o] Error 1
In Queue.h:
class Queue {
int* Q;
int oldest;
int newest;
int size;
int count;
public:
Queue(int sz);
In Queue.cpp:
Queue::Queue(int sz = 100)
:oldest(0), newest(-1), size(sz),count(0)
{Q = new int[size];}
In Sim.h:
class Sim:public Queue{
int served;
int totalresponse;
int maxresponse;
void arrival(int time);
void departure(int time);
void Print(ostream& o, char* t, int v, char* u);
public:
Sim();
In Sim.cpp:
Sim::Sim():served(0), totalresponse(0), maxresponse(0) {}
The files are all linked into a main program file and I am compiling with a makefile. I admit I do not fully understand how this constructor should be, but I modeled it off the constructors we have been using. Am I not right in thinking that the constructor should inherit the constructor for Queue and automatically construct Sim as a Queue?
include Queue.h
inside the Sim.h file? You need to because the Sim class references the Queue class. – Damien Black