 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Tue Nov 21, 2006 1:49 am Post subject: Pointer to an overloaded method, error: "unresolved overload |
|
|
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 |
|
 |
|
|
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
|
|