g++ doesn't find the right ctor
Matthias Kretz
Matthias.Kretz@kip.uni-heidelberg.de
Fri Sep 11 16:10:00 GMT 2009
Hi,
the following code does not compile:
struct A
{
template<typename T> A(const T *, const float *T::*) {}
};
struct B
{
float *f;
};
int main()
{
B x;
A y(&x, &B::f);
return 0;
}
Output is:
g++ -Wall -O3 -Wextra main.cpp -o test
main.cpp: In function ‘int main()’:
main.cpp:14: error: no matching function for call to ‘A::A(B*, float* B::*)’
main.cpp:2: note: candidates are: A::A(const A&)
It compiles if I change B to
struct B
{
const float *f;
};
or the A ctor to
template<typename T> A(const T *, float *T::*) {}
I believe g++ is at fault here. Or am I expecting too much?
Regards,
Matthias
More information about the Gcc-help
mailing list