1

I think this will make more sense if I put the code first:

I have a member variable defined as such:

std::queue<void (*)()> fptrs;

...and am trying to pop a pointer back out of it like this:

void (*f)() = fptrs.pop();

The 'alert' I get is this:

Assigning to 'void (*)()' from incompatible type 'void'

It seems that I'm not putting function pointers into my queue, or they're popping back out magically transformed. Either way, I'm not sure how to fix this, and I've fiddled with it for a bit.

Thanks for the help.

2 Answers 2

1

std::queue::pop() returns void. You need a call to std::queue::front(), followed by one to std::queue::pop().

I would suggest using a typedef for the function pointer, for the sake of readability.

Sign up to request clarification or add additional context in comments.

2 Comments

I knew I'd feel stupid when this got answered. Thanks a lot, I'll read the docs better next time!
@Tyler The interface is a bit non-intuitive. If you're interested, it is like this for reasons of exception safety.
0
#include <iostream>
#include <queue>
using namespace std;

typedef void (*pFun)();

void fun1(){ printf("fun1\n"); }
void fun2(){ printf("fun2\n"); }
int main()
{
    queue<pFun> d;
    d.push(fun1);
    d.push(fun2);

    pFun fun = d.front();
    fun();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.