I've read this question How to make a function return a pointer to a function? (C++)
...but I am still having a problem. The Index
function returns an enumerator function that takes a function to which it yields each index. The function signatures have been typedef
ed in Indexer.hpp:
typedef bool (*yield)(Core::Index*);
typedef int (*enumerator)(yield);
...and the Indexer
class
// Indexer.hpp
class Indexer {
public:
enumerator Index(FileMap*);
private:
int enumerate_indexes(yield);
};
// Indexer.cpp
enumerator Indexer::Index(FileMap* fMap) {
m_fmap = fMap;
// ...
return enumerate_indexes;
}
int Indexer::enumerate_indexes(yield yield_to) {
bool _continue = true;
while(_continue) {
Index idx = get_next_index();
_continue = yield_to(&idx);
}
return 0;
}
The compiler fails with the error below:
Indexer.cpp: In member function 'int (* Indexer::Index(FileMap*))(yield)':
Indexer.cpp:60:12: error: cannot convert 'Indexer::enumerate_indexes' from
type 'int (Indexer::)(yield) {aka int (Indexer::)(bool (*)(Core::Index*))}' to
type 'enumerator {aka int (*)(bool (*)(Core::Index*))}'
What am I missing in my declarations?