#ifndef TEST_H
#define TEST_H
void a (int, int);
void b (int, int);
void c (int, int);
class TheClass
{
public:
typedefvoid (*fnct) (int, int);
protected:
typedefstruct {
int id;
fnct fn;
} idfn_tuple;
staticconstexpr idfn_tuple list[] = {
{ .id = 0, .fn = a },
{ .id = 1, .fn = b },
{ .id = 2, .fn = c }
};
staticconst idfn_tuple * find ( int id );
};
#endif // TEST_H
// test.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "test.h"
void a (int, int) { /*Do nothing*/ }
void b (int, int) { /*Do nothing*/ }
void c (int, int) { /*Do nothing*/ }
const TheClass::idfn_tuple * TheClass::find ( int id )
{
return &list[id];
}
int main()
{
return 0;
}
// end of test.cpp
Output:
1 2 3 4
> g++ test.cpp
/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /tmp/cc5Dz4ZB.o: in function `TheClass::find(int)':
test.cpp:(.text+0x3a): undefined reference to `TheClass::list'
collect2: error: ld returned 1 exit status
Thank you for your reply. Indeed, shortly after posting we came to the same conclusion with a colleague of mine.
The really baffling thing is that the code WAS working until this morning, when we added an extra member at the end of the array. And we have been using g++11 all along. Mysteries of life.
We need to stay with c++11 so refactored the code. Thanks once again.