[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] C++ Syntax Question
From: |
Matthijs Kooijman |
Subject: |
Re: [avr-gcc-list] C++ Syntax Question |
Date: |
Mon, 7 Jul 2014 15:38:56 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hey Thomas,
> My initial thought was to use function pointers and a list. If the
> function is defined outside the class, I can add it to the list. f1
> in the example. If the function is declared in the class, I get a
> compile error, f2 in the example. I have tried qualifying f2, etc.
> No luck.
Showing the compiler error message would have been helpful. I suspect
you'll have seen some type error, since you didn't make f2 a static
function.
> class MyList {
> private:
> list<bool (*)(void)> list1;
> bool f2(void);
Here, f2 is a normal (non-static) member function, meaning it should be
called _on_ an object (under water it actually has an extra "this"
argument).
I think declaring f2 as a static member function would fix you problem.
If you need f2 to remain a normal function, you'll have to create a
list that stores both the member function to call, as well as the object
to call it on. Google for "member function pointer" for more info.
Gr.
Matthijs
signature.asc
Description: Digital signature