Nov 30, 2013 at 4:00pm Nov 30, 2013 at 4:00pm UTC
Hello, I've been having a problem I can't seem to solve on ym own whole day. I'm really new to C++ so I hope you can give me a hand.
I have a class Calendar which has an attribute of priority queue, that accepts records of structure defined as:
1 2 3 4 5 6 7
typedef void (Calendar::*eventPointer)();
struct activationRecord {
double Time;
int Priority;
eventPointer activationEvent;
};
And here is the problem. Whole day I've been trying to fill the Calendar with some test entries by calling the method
void Calendar::calendarPush(double Time, int Priority, eventPointer event)
This is how I call it
calendar.calendarPush(Time, Priority, &Calendar::calendarEmpty);
But Visual Studio keeps to warn me with this error
argument of type "bool (Calendar::*)()" is incompatible with parameter of type "eventPointer *"
Does anyone know what I am doing wrong?
Thank you, I'm starting to be really depressed about this as I've been stuck whole day, unable to solve this.
If it helps, here is a whole CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
#include <iostream>
#include "Calendar.h"
using namespace std;
int main() {
cout << "Initializing ..." << endl;
double Time = 0.0;
int Priority = 0;
Calendar calendar;
cout << "Pushing first activation record .." << endl;
calendar.calendarPush(Time, Priority, &Calendar::calendarEmpty);
}
----------CALENDAR.H------------
#include <iostream>
#include <queue>
using namespace std;
typedef void (Calendar::*eventPointer)();
struct activationRecord {
double Time;
int Priority;
eventPointer activationEvent;
};
bool operator <(const activationRecord & a, const activationRecord & b) {
return a.Time > b.Time;
}
class Calendar {
private:
std::priority_queue<activationRecord> activationCalendar;
public:
bool calendarEmpty();
void calendarPush(double, int, eventPointer);
activationRecord calendarTop();
void calendarPop();
};
----------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();
}
Last edited on Nov 30, 2013 at 4:24pm Nov 30, 2013 at 4:24pm UTC
Nov 30, 2013 at 4:59pm Nov 30, 2013 at 4:59pm UTC
I have a class Calendar which has an attribute of priority queue, that accepts records of structure defined as:
typedef void (Calendar::*eventPointer)();
This is how I call it:
calendar.calendarPush(Time, Priority, &Calendar::calendarEmpty);
But Visual Studio keeps to warn me with this error
argument of type "bool (Calendar::*)()" is incompatible with parameter of type "eventPointer *"
Notice that the return type for your
eventPointer typedef is
void while the return type of
Calendar::calendarEmpty is
bool which is what the diagnostic is indicating.
Last edited on Nov 30, 2013 at 4:59pm Nov 30, 2013 at 4:59pm UTC
Nov 30, 2013 at 5:31pm Nov 30, 2013 at 5:31pm UTC
I think something is different with your code than what you're posting.
argument of type "void (Calendar::*)()" is incompatible with parameter of type "eventPointer *"
Your
Calendar::push signature doesn't take a value of type
eventPointer* . It takes a value of type
eventPointer .
Does this simple code compile for you?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
struct A
{
typedef void (A::*eventType)();
void eventFunc() {std::cout << "eventFunc()\n" ;}
eventType func;
};
int main()
{
A a;
a.func = &A::eventFunc;
(a.*a.func)(); // invoke the pointer with object a
}
You may find
http://www.parashift.com/c++-faq/pointers-to-members.html helpful.
Last edited on Nov 30, 2013 at 5:35pm Nov 30, 2013 at 5:35pm UTC