C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pointer to an overloaded method, error: "unresolved overload

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Tue Nov 21, 2006 1:49 am    Post subject: Pointer to an overloaded method, error: "unresolved overload Reply with quote



Error: unresolved overloaded function type

g++ source.cpp
04_overloaded_unresolv.cpp: In member function `void wrapper_c::method1
()':
04_overloaded_unresolv.cpp:75: error: no matching function for call to
`wrapper_c::executeDirectly(<unresolved overloaded function type>,
std::string&, std::string&)'

This happens, if the method is overloaded.
Do you know how this could be solved? (How to make it work with
overloaded methods.)
g++ -v 3.4.5

#include <iostream>
#include <string>
#include <vector>
using std::vector;
using std::string;
using std::cout;
using std::endl;

// Pointers to methods.
// www.codeproject.com/cpp/FastDelegate.asp

class target_c
{
public:

string* targetMethod(string& p1, string& p2)
{ return new string("stringString");
}
// If this is taken in use, then the error message pops up in
compilation "unresolved overloaded function type"
//string* targetMethod(const string& p1, const int& p2)
//{ return new string("stringInt"); }
};

template <class CHILD>
class common_c
{
public:

template <class RETURN_CLASS, class T1, class P1, class P2>
RETURN_CLASS executeDirectly(RETURN_CLASS (T1::*my_memfunc_ptr)(P1&,
P2&),
P1& param1,
P2& param2)
{
try
{
return new string("test");
//return
//(
// ((static_cast<CHILD*>(this))->getPointer())
// ->*my_memfunc_ptr
// )
// (param1, param2);
//return (static_cast<CHILD*>(this)->*my_memfunc_ptr)(param1,
param2);
}
catch (int& e)
{
string ex;
ex = e;
throw ex;
}
}

};

class wrapper_c : public common_c<wrapper_c> {
public:

target_c* target_;

target_c* getTarget() {return target_;}


wrapper_c ()
{ target_ = new target_c();}

void method1 ()
{
string arg1("");
string arg2("");
string* returnVal;

// This line gives the error message during compilation:
returnVal = executeDirectly<string*>(&target_c::targetMethod, arg1,
arg2);

std::cout << *returnVal << std::endl;
}

private:



};

int main()
{
cout << "in MAIN, start" << endl;

// This works ok:
string* (target_c::*my_memfunc_ptr)(string&, string&);
my_memfunc_ptr = &target_c::targetMethod;
string a1("a1"), a2("a2");
string* ret;
target_c target;
ret = (target.*my_memfunc_ptr)(a1,a2);
cout << "called" << endl;
cout << *ret << endl;

// But this do not work::
wrapper_c wrapper;
wrapper.method1();

}


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.