|
From: Daniel Krügler on 8 Apr 2008 07:53 On 8 Apr., 21:36, Thomas Maeder <mae...(a)glue.ch> wrote: > Daniel Kr�gler <daniel.krueg...(a)googlemail.com> writes: > > On 8 Apr., 00:26, Thomas Maeder <mae...(a)glue.ch> wrote: > >> Try this: > > >> template <typename A, typename B> > >> class D<A, B, void (A::*)(B)> > >> { > > >> }; > > >> template <typename A> > >> class D<A, void, void (A::*)()> > >> { > > >> }; > > > Hmmh, OK, I throw in the towel: *How* did you define the > > primary class template that this works as written?? > > template <typename A, typename B, typename C> > class D > { > > }; > > [You are right, that there is a blatant typo in the OP, but > > I don't think that above specialization is correct. For more > > details, see my seperate posting] > > I don't understand your point. Maybe because I don't understand the > OP's intention, and you do. Or maybe vice versa :-) Touch�! ;-) OK, I have to that I confess that I was a bit blinded by my prejudice that I *expected* that the OP meant the third parameter to be a non-type template parameter. But if we look at the very last line of the OP, "class C<A, void, void (T::*MF)()>" I can only scratch my head, because I don't understand anything anymore.... Greetings from Bremen, Daniel -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Greg Herlihy on 9 Apr 2008 04:19
On Apr 7, 9:13 am, Road Dog <no...(a)nowhere.com> wrote: > template <typename A, typename B, void (A::*MF)(B)> > class D > { > }; > > template <typename A, void (A::*MF)()> > class D<A, void, MF> > class D > { > }; > > produces: > > test4.cc:17: error: invalid parameter type 'void' > test4.cc:12: error: in declaration 'template<class T, class W, void > > Is there some way to specialize on 'void' here ? Yes - use a "helper" class template. For example: // General helper class template template <class T, class P> struct MemberPointerHelper { typedef void (T::*type)(P); }; // Partial specialization for "void" parameter template <class T> struct MemberPointerHelper<T, void> { typedef void (T::*type)(); }; // The "D" class template now uses MemberPointerHelper // to specify the member function pointer type // of its non-type, third template parameter template <class A, class B, typename MemberPointerHelper<A, B>::type MF> class D { }; // Test class struct S { void f1(int i){} void f2(){} }; int main() { D<S, int, &S::f1> d1; // OK D<S, void, &S::f2> d2; // OK } Greg -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |