I want to have a template class with 2 templates parameter: A Container class and a member pointer pointing to an array of values.
I've following Example:
template<class CONTAINER,int * CONTAINER::*SomeMember>
struct Foo {
Foo(CONTAINER *container) {
this->value = container->*SomeMember;
this->container = container;
}
CONTAINER *container;
int value;
};
struct Bar1 {
char bla;
int y[42];
};
struct Bar2 {
int blablab;
char bla;
int y[42];
};
struct Bar3 {
int * x;
};
void TEST() {
Bar1 b1;
Bar2 b2;
Bar3 b3;
//This one fails with
// error: could not convert template argument '&Bar1::y' to 'int* Bar1::*'
// error: invalid conversion from 'Bar1*' to 'int' [-fpermissive]
Foo<Bar1,&Bar1::y> foo3(&b1);
//This fails too
Foo<Bar2,&Bar2::y> foo2(&b2);
//This is working
Foo<Bar3,&Bar3::x> foo(&b3);
}
The stuff is working fine as long as I don't use the fixed size arrays.
What does I have to correct to have this example working? The most important part for me is to have the example working with the Bar1 and Bar2.