[LC++]C++ Template Instantiation problems

Charles Randle charlesrandle at yahoo.com
Tue Sep 3 10:56:06 UTC 2002


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 ?

Best Regards,
Charles Randle

--- Dr Mark H Phillips <mark at austrics.com.au> wrote:
> Hi Charles,
> 
> I compiled your code on my machine, using gcc
> version 2.95.4
> and got error messages which are a bit different
> from what you
> reported.  I include them below. Hopefully they are
> helpful to 
> you.
> 
> Cheers,
> 
> Mark.
> 
> 
> 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::*)()'
> 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




More information about the tuxCPProgramming mailing list