I've been having some trouble finding the cause of error in my code and I would like to ask you for help. I already asked about similar problem yesterday but then I thought i found out the cause. The compiler proved me wrong once again this morning ...
The errors say:
IntelliSense: argument of type "void (Transaction::*)()" is incompatible with parameter of type "eventPointer"
error C2664: 'Calendar::calendarPush' : cannot convert parameter 3 from 'void (__thiscall Transaction::* )(void)' to 'eventPointer'
the code causing the errors can eb found in
Main.cpp, line (calling of the method)
Calendar::calendarPush(1, 1, &Transaction::event1);
and
Calendar.cpp line (definition of the method)
void Calendar::calendarPush(double Time, int Priority, eventPointer event)
the definition of eventPointer can found in
Calendar.h, line
typedef void (Calendar::*eventPointer) ();
I don't see how are those two incompatible. What's wrong? :/
Here is the code:
----------MAIN.CPP----------
#include <iostream>
#include "Calendar.cpp"
#include "Transaction.cpp"
using namespace std;
int main() {
cout << "Initializing" << endl;
double Time = 0.0;
int Priority = 0;
cout << "Pushing initial event" << endl;
Calendar::calendarPush(1, 1, &Transaction::event1);
}
----------CALENDAR.H----------
#include <iostream>
#include <queue>
using namespace std;
class Calendar;
typedef void (Calendar::*eventPointer) ();
struct activationRecord {
double Time;
int Priority;
eventPointer activationEvent;
};
bool operator < (const activationRecord & a, const activationRecord & b);
class Calendar {
private:
static std::priority_queue<activationRecord> activationCalendar;
public:
bool calendarEmpty();
static void calendarPush(double, int, eventPointer);
activationRecord calendarTop();
void calendarPop();
void calendarRun();
};
----------CALENDAR.CPP-----------
#include "Calendar.h"
bool Calendar::calendarEmpty() {
return activationCalendar.empty();
}
void Calendar::calendarPush(double Time, int Priority, eventPointer event) {
activationRecord record;
record.Time = Time;
record.Priority = Priority;
record.activationEvent = event;
activationCalendar.push(record);
}
activationRecord Calendar::calendarTop() {
return activationCalendar.top();
}
void Calendar::calendarPop() {
activationCalendar.pop();
}
void Calendar::calendarRun() {
activationRecord record;
while(!calendarEmpty()) {
record = calendarTop();
calendarPop();
cout << record.Time << endl;
cout << record.Priority << endl;
cout << record.activationEvent << endl << endl;
}
}
bool operator < (const activationRecord & a, const activationRecord & b) {
return a.Time > b.Time;
}
----------TRANSACTION.H----------
#include <iostream>
using namespace std;
class Transaction {
public:
void event1();
void event2();
void event3();
void event4();
void event5();
};
----------TRANSACTION.CPP-----------
#include <iostream>
#include "Transaction.h"
using namespace std;
void event1() {
cout << "event1" << endl;
}
void event2() {
cout << "event2" << endl;
}
void event3() {
cout << "event3" << endl;
}
void event4() {
cout << "event4" << endl;
}
void event5() {
cout << "event5" << endl;
}
Now all of the sudden Im getting even more errors which make even less sense to me.
error C2027: use of undefined type 'Transaction'
error C2065: 'event1' : undeclared identifier
error C2011: 'Transaction' : 'class' type redefinition
I just don't uderstand how something like this can happen, it seems to in direct disaccord in what my code contains.
I will rather paste whole code again in case i screwed up something i cant see:
----------MAIN.CPP----------
#include <iostream>
#include "Calendar.h"
#include "Transaction.h"
using namespace std;
int main() {
cout << "Inicializuji" << endl;
double Time = 0.0;
int Priority = 0;
cout << "Vlkadam uvodni udalost" << endl;
Calendar::calendarPush(1, 1, &Transaction::event1);
}
----------CALENDAR.H----------
#include <iostream>
#include <queue>
#include "Transaction.h"
using namespace std;
typedef void (Transaction::*eventPointer) ();
struct activationRecord {
double Time;
int Priority;
eventPointer activationEvent;
};
bool operator < (const activationRecord & a, const activationRecord & b);
class Calendar {
private:
static std::priority_queue<activationRecord> activationCalendar;
public:
bool calendarEmpty();
static void calendarPush(double, int, eventPointer);
activationRecord calendarTop();
void calendarPop();
void calendarRun();
};
----------CALENDAR.CPP-----------
#include "Calendar.h"
bool Calendar::calendarEmpty() {
return activationCalendar.empty();
}
void Calendar::calendarPush(double Time, int Priority, eventPointer event) {
activationRecord record;
record.Time = Time;
record.Priority = Priority;
record.activationEvent = event;
activationCalendar.push(record);
}
activationRecord Calendar::calendarTop() {
return activationCalendar.top();
}
void Calendar::calendarPop() {
activationCalendar.pop();
}
void Calendar::calendarRun() {
activationRecord record;
while(!calendarEmpty()) {
record = calendarTop();
calendarPop();
cout << record.Time << endl;
cout << record.Priority << endl;
cout << record.activationEvent << endl << endl;
}
}
bool operator < (const activationRecord & a, const activationRecord & b) {
return a.Time > b.Time;
}
----------TRANSACTION.H----------
#include <iostream>
using namespace std;
class Transaction {
public:
void event1();
};
----------TRANSACTION.CPP-----------
#include "Transaction.h"
using namespace std;
void Transaction::event1() {
}
Ty for any help.