Re: C++ Syntax Question

Matthijs Kooijman <[email protected]>
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <[email protected]>
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

_______________________________________________
AVR-GCC-list mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
signature.asc (application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlO6ou8ACgkQz0nQ5oovr7yl7ACgy8q5qKS6uBsw41uWduXQA4/X
aEAAn36D+TFTw695zUwGjZsIix8F1fOY
=g0+2
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.