[LC++]C++ Template Instantiation problems
Trevor Spiteri
tspiteri at ieee.org
Thu Oct 24 22:53:01 UTC 2002
Two months late, but anyway,
Your code contains three problems:
1) You use a reference for the member function (CLIENTMEMBER &). Don't
use a reference. Replace your use of "CLIENTMEMBER &" with just
"CLIENTMEMBER" and "MEMBER &" with "MEMBER".
This is the problem that caused your compiler error.
2) In gx_memberCB, you declare the operator() as non-const, whereas in
the abstract base class it is const.
3) In the same function, you use ->*member instead of ->*clientmember.
Trevor Spiteri
On Sat, 2002-08-31 at 03:51, 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
>
More information about the tuxCPProgramming
mailing list