problem with pure virtual funtions

closed account (zhq4izwU)
I have specifically a problem when trying to run part of the code for the constructor of the derived class SignalChangedEvent.

I have the following class Event:

1
2
3
4
5
6
7
8
9
10
11
12
class Event
{

public:
	// Construct sets time of event.
	Event (unsigned int t) : time (t) { }

	// Execute event by invoking this method.
	virtual void processEvent () = 0;

	const unsigned int time;
};


Furthermore, there's a derived class called: SignalChangedEvent in the .h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "simulate.h"
#include "wire.h"
#include "component.h"  
using namespace std;

class SignalChangedEvent : public Event
{
private:
    Wire *wire;
	bool value;
public:

	SignalChangedEvent(unsigned int, Wire * , bool);
	
	virtual void processEvent(bool);
};


The different functions of the derived class are put here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "digital_sim.h"
SignalChangedEvent::SignalChangedEvent(unsigned int t, Wire *  vector, bool v)
{
	time= t;
	value = v;
	outputWires[i]= value;

}
void SignalChangedEvent::processEvent (bool a)
{
	value = a;
	wire->set_value(value);
	wire->process();
}


I get an error when running this part of the code:
1
2
3
4
5
6
7
void And2::process()
{
	bool outputValue = inputBits[0] & inputBits[1];

for (unsigned int i = 0; i < outputWires.size(); i++)
		theSimulation.scheduleEvent(new SignalChangedEvent(theSimulation.time + delay, outputWires[i], outputValue));
}


It says:
error: cannot allocate an object of abstract type 'SignalChangedEvent'
note: because the following virtual functions are pure within 'SignalChangedeEvent'

I have looked through the whole thing a couple of times, but I can't seem to find the problem in it.
Any help? :(
Your function signatures for processEvent are different between class Event and class SignalChangedEvent.

virtual void processEvent () = 0;

virtual void processEvent(bool);

The first takes no arguments, while the second is expecting a bool.
The compiler will see these as different functions and the second will not override the pure virtual.

closed account (zhq4izwU)
Thanks! That was really helpful! :)
Topic archived. No new replies allowed.