[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] C++ Syntax Question
From: |
Thomas D. Dean |
Subject: |
[avr-gcc-list] C++ Syntax Question |
Date: |
Mon, 07 Jul 2014 00:08:29 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 |
Sorry, if this is off topic.
I have an application where I want to call a group of functions, in turn.
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.
I think this is because of my lack of understanding...
I compile with g++ -c -I. mylist.cc -o mylist.o
What is the proper syntax?
Tom Dean
> cat mylist.h
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
class MyList {
private:
list<bool (*)(void)> list1;
bool f2(void);
public:
MyList();
void do_list();
};
> cat mylist.cc
#include <iostream>
#include <list>
#include <algorithm>
#include <mylist.h>
using namespace std;
bool f1(void) {
cout << "f1" << endl;
return true;
}
bool MyList::f2(void) {
cout << "f2" << endl;
return true;
}
MyList::MyList() {
list1.push_back(f1);
list1.push_back(f2);
}
- [avr-gcc-list] C++ Syntax Question,
Thomas D. Dean <=