[LC++]C++ Template Instantiation problems

Dr Mark H Phillips mark at austrics.com.au
Tue Sep 3 19:16:13 UTC 2002


On Tue, 2002-09-03 at 03:13, Charles Randle wrote:
> Mark,
> 
> Thanks for your response. I am actually using gcc
> version 3.2. I had a look at the code and tried some
> changes in light of the errors you sent and still got
> the same errors as before.But thanks for your help.Any
> ideas as to why this code snippet does not compile ?

I've tried to work it out, but it seems my C++ skills
are not advanced enough yet.

> > cr2.cc: In function `int main(int, const char *const
> > *)':
> > cr2.cc:67: initialization of non-const reference
> > type `void (A::* &)()'
> > cr2.cc:67: from rvalue of type `void (A::*)()'

In particular, it is not clear to me how the types
"void (A::* &)()" and "void (A::*)()" should be read.
Should the second one be read as: "A function that takes
no normal parameters and returns void, but has a special
"this" parameter, namely a pointer to A"?  But then why
isn't the type simply "void (A*)()"?

I don't know if this will help you, but the FC++ library
(which I can highly recommend), has callback example code
as part of the distribution.

http://www.cc.gatech.edu/~yannis/fc++/

Cheers,

Mark.

> > cr2.cc:47: in passing argument 2 of
> > `gx_callback::make_M2<A, void
> > (A::*)()>(A &,
> > void (A::* &)())'
> > cr2.cc: In function `static class gx_callback
> > gx_callback::make_M2<A,
> > void (A::*)()>(A &, void (A::* &)())':
> > cr2.cc:67:   instantiated from here
> > cr2.cc:49: cannot allocate an object of type
> > `gx_memberCB<A,void
> > (A::*)()>'
> > cr2.cc:49:   since the following virtual functions
> > are abstract:
> > cr2.cc:7:       void gx_callbackBaseBody::operator
> > ()() const
> > 
> > 
> > 
> > 
> > On Sat, 2002-08-31 at 01:17, Charles Randle wrote:
> > > Hi All,
> > > This is a repost due to an email address change :
> > > 
> > > I have the following code :
> > > #include <iostream>
> > > 
> > >   class gx_callbackBaseBody {
> > >   public:
> > >     gx_callbackBaseBody() {}
> > >     virtual ~gx_callbackBaseBody() {}
> > >     virtual void operator ()() const = 0;
> > >   };
> > > 
> > > 
> > > 
> > >   class gx_callback {
> > >   public:
> > > 
> > >     gx_callback(gx_callbackBaseBody *ptr) :
> > > entity(ptr) {}
> > >     gx_callback(gx_callback const & arg) :
> > > entity(arg.entity) {}
> > >     ~gx_callback() { delete entity;entity =
> > 0;return;}
> > >     void operator ()() { (*entity)();}
> > > 
> > >     template <class CLIENT,class CLIENTMEMBER>
> > >     static gx_callback make_M2(CLIENT
> > &,CLIENTMEMBER
> > > &);
> > > 
> > >   private:
> > >     gx_callbackBaseBody *entity;
> > >   };
> > > 
> > > 
> > > 
> > >   template <class CLIENT,class MEMBER>
> > >   class gx_memberCB : public gx_callbackBaseBody {
> > >   public:
> > >     gx_memberCB(CLIENT &clnt,MEMBER &clntmem) :
> > > client(clnt),clientmember(clntmem) {}
> > >     virtual void operator () () { ((&client)
> > > ->*member)();}
> > > 
> > >   private:
> > >     CLIENT &client;
> > >     MEMBER &clientmember;
> > >   };
> > > 
> > >   template <class CLIENT,class CLIENTMEMBER>
> > >   gx_callback gx_callback::make_M2(CLIENT
> > > &c,CLIENTMEMBER &cm) {
> > >     return gx_callback(new
> > > gx_memberCB<CLIENT,CLIENTMEMBER>(c,cm));
> > >   }
> > > 
> > > 
> > > class A {
> > > public:
> > >   A(){}
> > >   ~A(){}
> > >   void noretsnoargs() {::std::cerr << "NO returns
> > & No
> > > Args !!" << ::std::endl;return;}
> > >  };
> > > 
> > > 
> > > int main (int argc,char const * const * const
> > argv) {
> > > 
> > >   A objectA;
> > > 
> > >   gx_callback test1
> > > (gx_callback::make_M2(objectA,&A::noretsnoargs));
> > >   //
> > >   // Execute object
> > >   test1();
> > > }
> > > 
> > > 
> > > Which gives the following error on compilation:
> > > 
> > > g++     cbtest.cpp   -o cbtest
> > > cbtest.cpp: In function `int main(int, const char*
> > > const*)':
> > > cbtest.cpp:62: no matching function for call to
> > > `gx_callback::make_M2(A&, void
> > >    (A::*)())'
> > > cbtest.cpp:42: candidates are: static gx_callback
> > > gx_callback::make_M2(CLIENT&,
> > >    CLIENTMEMBER&) [with CLIENT = A, CLIENTMEMBER =
> > > void (A::*)()]
> > > make: *** [cbtest] Error 1
> > > 
> > > 
> > > Can anyone explain this and possibly suggest a
> > > solution.
> > > 
> > > Best Regards,
> > > Charles Randle
> > > 
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Yahoo! Finance - Get real-time stock quotes
> > > http://finance.yahoo.com
> > > 
> > > _______________________________________________
> > > This is the Linux C++ Programming List
> > > :
> > http://lists.linux.org.au/listinfo/tuxcpprogramming
> > List
> > -- 
> > Dr Mark H Phillips
> > Research Analyst (Mathematician)
> > 
> > AUSTRICS - smarter scheduling solutions -
> > www.austrics.com
> > 
> > Level 2, 50 Pirie Street, Adelaide SA 5000,
> > Australia
> > Phone +61 8 8226 9850
> > Fax   +61 8 8231 4821
> > Email mark at austrics.com.au
> > 
> > 
> > _______________________________________________
> > This is the Linux C++ Programming List
> > :
> > http://lists.linux.org.au/listinfo/tuxcpprogramming
> List
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Finance - Get real-time stock quotes
> http://finance.yahoo.com
> 
> _______________________________________________
> This is the Linux C++ Programming List
> : http://lists.linux.org.au/listinfo/tuxcpprogramming List
-- 
Dr Mark H Phillips
Research Analyst (Mathematician)

AUSTRICS - smarter scheduling solutions - www.austrics.com

Level 2, 50 Pirie Street, Adelaide SA 5000, Australia
Phone +61 8 8226 9850
Fax   +61 8 8231 4821
Email mark at austrics.com.au





More information about the tuxCPProgramming mailing list