This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Pointer-to-member type matching in template class


Again I'm unable to determine if the behaviour is correct or buggy. If this is the wrong forum, sorry...

The following snippet declares Closure<C,T> as a pair consisting of a pointer to an object B and a pointer-to-member into B. The constructor accepts a reference to a B and a pointer to a suitable B member, and saves them.

The example class Test has a member of type T, where typedef int T ().

In the example function test(), an _assignment_ to a variable of type T Test::* is allowed, but the corresponding parameterization (for the constructor) is not allowed. The error message is (mysteriously)

foo.cpp: In function `void test()':
foo.cpp:25: no matching function for call to `Closure<Test,int ()()>::Closure (Test &, int (Test::*)())'
foo.cpp:25: candidates are: Closure<Test,int ()()>::Closure(const Closure<Test,int ()()> &)
foo.cpp:5: Closure<Test,int ()()>::Closure<Test, int ()()>(Test &, int ( Test::*)())

I say mysteriously because the only apparent difference between the type declared (reported as "int ( Test::*)()") and the type supplied (reported as "int (Test::*)()") is a single space character.

Here's the snippet:

template <class B, class T> struct Closure
{
B *object;
T B::* ptr;
Closure (B& o, T B::* p) {object = &o; ptr = p;}
};

typedef int T ();

struct Test
{
int x;
T foo;
};

void test ()
{
Test x;

T Test::* u;
u = &Test::foo;

Closure<Test,T> c (x, &Test::foo);
}

--
Andrew Malton
Department of Computer Science
University of Waterloo
Waterloo, Canada N2L 3G1

http://www.cs.uwaterloo.ca/~ajmalton
tel: +1 519 888 4567 x 5144
fax: +1 519 885 1208


--
Dr. Andrew Malton, Associate Professor
Department of Computer Science
University of Waterloo
Waterloo, Canada N2L 3G1

http://www.cs.uwaterloo.ca/~ajmalton
tel: +1 519 888 4567 x 5144
fax: +1 519 885 1208


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]