[LC++]C++ Template Instantiation problems

Charles Randle charlesrandle at yahoo.com
Sat Aug 31 01:51:05 UTC 2002


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




More information about the tuxCPProgramming mailing list