Linker problem
-
toxcct wrote:
dear alok what does the compiler or the linker say ?
Ohh Sorry!, here is what compiler/linker says :)
D:\Alok\Test Project\cpp\11.cpp(70) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
D:\Alok\Test Project\cpp\11.cpp(78) : error C2664: '__thiscall
CTextDropTarget::CTextDropTarget(bool (__thiscall CSACAddressListCtrl::*)
(int,int))' :
cannot convert parameter 1 from 'bool (__cdecl *)(int,int)' to 'bool (__thiscall CSACAddressListCtrl::*)(int,int)'
There is no context in which this conversion is possible
Error executing cl.exe."Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV -- modified at 8:23 Thursday 22nd December, 2005
this is a compiler error (not a linker one. it says that it cannot convert a __cdecl function pointer to a __thiscall one... i don't know why it does happen, but you might try to call a global function thinking it is a class member.
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VisualCalc 3.0] -
this is a compiler error (not a linker one. it says that it cannot convert a __cdecl function pointer to a __thiscall one... i don't know why it does happen, but you might try to call a global function thinking it is a class member.
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VisualCalc 3.0]toxcct wrote:
i don't know why it does happen, but you might try to call a global function thinking it is a class member.
Any other solution!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
this is a compiler error (not a linker one. it says that it cannot convert a __cdecl function pointer to a __thiscall one... i don't know why it does happen, but you might try to call a global function thinking it is a class member.
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VisualCalc 3.0]toxcct wrote:
i don't know why it does happen
It is because the prototypes for a normal function (__cdecl) and a member function of a class (__thiscall) are different. For the class function, an extra parameter is passed implicitely which is the this parameter (in order for the function to be able to know which instance of the class called her). Two solution: change the function to a global function (which is not really appropriate) or change it into a static function. A static function (member of a class) is shared among all instances of that class thus, it doesn't require the implicit this parameter but this also implies that you cannot use non-static members (functions or variables) of the class.
-
HI EveryBody, I am facing a problem... i am not able to compile this code.. could any body suggest me work around for following code :-
#include <iostream.h>
typedef int wxCoord ;template <class T>
class CTextDropTarget
{
private:
bool (T::*m_pt2CallbackFunc)(wxCoord x, wxCoord y);
public:
CTextDropTarget(bool (T::*pt2Func)(wxCoord x, wxCoord y));
virtual ~CTextDropTarget(void);
virtual bool OnDropText(wxCoord x, wxCoord y);};
template <class T>
CTextDropTarget<T>::CTextDropTarget(bool ( T::*pt2Func)(wxCoord x, wxCoord y))
{
m_pt2CallbackFunc=pt2Func;}
template <class T>
CTextDropTarget<T::~CTextDropTarget(void)
{
}template <class T>
bool CTextDropTarget<T>::OnDropText(wxCoord x, wxCoord y)
{
return false;
}class CSACAddressListCtrl
{
public:
CTextDropTarget<CSACAddressListCtrl> *m_pDropTarget;
static bool OnTextDropTarget(wxCoord x, wxCoord y)
{
return x+y;
}
};void main()
{
CTextDropTarget* m_pDropTarget = new CTextDropTarget<CSACAddressListCtrl>( &CSACAddressListCtrl::OnTextDropTarget);}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV -- modified at 8:01 Thursday 22nd December, 2005
Remove the static keyword from the OnTextDropTarget function in your CSACAddressListCtrl class. The constructor of your template class expects a member function of your class (template) thus if this function is static, the prototype is different ( see my other post in response to toxcct).
-
HI EveryBody, I am facing a problem... i am not able to compile this code.. could any body suggest me work around for following code :-
#include <iostream.h>
typedef int wxCoord ;template <class T>
class CTextDropTarget
{
private:
bool (T::*m_pt2CallbackFunc)(wxCoord x, wxCoord y);
public:
CTextDropTarget(bool (T::*pt2Func)(wxCoord x, wxCoord y));
virtual ~CTextDropTarget(void);
virtual bool OnDropText(wxCoord x, wxCoord y);};
template <class T>
CTextDropTarget<T>::CTextDropTarget(bool ( T::*pt2Func)(wxCoord x, wxCoord y))
{
m_pt2CallbackFunc=pt2Func;}
template <class T>
CTextDropTarget<T::~CTextDropTarget(void)
{
}template <class T>
bool CTextDropTarget<T>::OnDropText(wxCoord x, wxCoord y)
{
return false;
}class CSACAddressListCtrl
{
public:
CTextDropTarget<CSACAddressListCtrl> *m_pDropTarget;
static bool OnTextDropTarget(wxCoord x, wxCoord y)
{
return x+y;
}
};void main()
{
CTextDropTarget* m_pDropTarget = new CTextDropTarget<CSACAddressListCtrl>( &CSACAddressListCtrl::OnTextDropTarget);}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV -- modified at 8:01 Thursday 22nd December, 2005
a question from ALOK??? :~, that should be a real question.:)
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho
--[V]--
-
HI EveryBody, I am facing a problem... i am not able to compile this code.. could any body suggest me work around for following code :-
#include <iostream.h>
typedef int wxCoord ;template <class T>
class CTextDropTarget
{
private:
bool (T::*m_pt2CallbackFunc)(wxCoord x, wxCoord y);
public:
CTextDropTarget(bool (T::*pt2Func)(wxCoord x, wxCoord y));
virtual ~CTextDropTarget(void);
virtual bool OnDropText(wxCoord x, wxCoord y);};
template <class T>
CTextDropTarget<T>::CTextDropTarget(bool ( T::*pt2Func)(wxCoord x, wxCoord y))
{
m_pt2CallbackFunc=pt2Func;}
template <class T>
CTextDropTarget<T::~CTextDropTarget(void)
{
}template <class T>
bool CTextDropTarget<T>::OnDropText(wxCoord x, wxCoord y)
{
return false;
}class CSACAddressListCtrl
{
public:
CTextDropTarget<CSACAddressListCtrl> *m_pDropTarget;
static bool OnTextDropTarget(wxCoord x, wxCoord y)
{
return x+y;
}
};void main()
{
CTextDropTarget* m_pDropTarget = new CTextDropTarget<CSACAddressListCtrl>( &CSACAddressListCtrl::OnTextDropTarget);}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV -- modified at 8:01 Thursday 22nd December, 2005
Basically what Cedric said. For static functions, the declaration of the pointer to the function does include the classname. So if you had
bool (*m_pt2CallbackFunc)(wxCoord x, wxCoord y);
instead of
bool (T::*m_pt2CallbackFunc)(wxCoord x, wxCoord y);
your code would have worked. If you do have the classname prefixed, you can only pass non-static member functions of T. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
Basically what Cedric said. For static functions, the declaration of the pointer to the function does include the classname. So if you had
bool (*m_pt2CallbackFunc)(wxCoord x, wxCoord y);
instead of
bool (T::*m_pt2CallbackFunc)(wxCoord x, wxCoord y);
your code would have worked. If you do have the classname prefixed, you can only pass non-static member functions of T. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
S. Senthil Kumar wrote:
Basically what Cedric said. For static functions, the declaration of the pointer to the function does include the classname. So if you had bool (*m_pt2CallbackFunc)(wxCoord x, wxCoord y);
I know about that method... but I am trying to use templates with function pointer! any suggestion
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
Remove the static keyword from the OnTextDropTarget function in your CSACAddressListCtrl class. The constructor of your template class expects a member function of your class (template) thus if this function is static, the prototype is different ( see my other post in response to toxcct).
Cedric Moonen wrote:
Remove the static keyword from the OnTextDropTarget function in your CSACAddressListCtrl class.
Hai Cedric, I know that way... but i am looking for templatized solution... which i believe not that simple :)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
S. Senthil Kumar wrote:
Basically what Cedric said. For static functions, the declaration of the pointer to the function does include the classname. So if you had bool (*m_pt2CallbackFunc)(wxCoord x, wxCoord y);
I know about that method... but I am trying to use templates with function pointer! any suggestion
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
I don't get it. Are you saying you want to solve the problem without changing the function pointer signature and the static modifier? The problem you have is not in any way related to templates, it's because you are passing a wrong function to be assigned to a function pointer. Take this class for example.
class X
{
public:
static void Y(bool x)
{
}
};Now if the function pointer is typedeffed to
typedef void (*Func)(bool x);
, you can doFunc f = &X::Y;
. However, if the function pointer is typedeffed totypedef void (*X::Func)(bool x);
, you can't doFunc f = &X::Y;
. That's because X::Func implies that the first (or last) parameter of the function pointed to by Func is the "this" pointer (thiscall calling convention). Because static functions don't take the "this" pointer as a parameter, the compiler will rejectFunc f = &X::Y;
. The solution is to remove the static modifier from Y, or, change the typedef by removing the X:: prefix. Regards Senthil _____________________________ My Blog | My Articles | WinMacro -
a question from ALOK??? :~, that should be a real question.:)
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho
--[V]--
VivekuniQ wrote:
a question from ALOK???, that should be a real question
Why! Isn't I am human being... I have problems too..
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
I don't get it. Are you saying you want to solve the problem without changing the function pointer signature and the static modifier? The problem you have is not in any way related to templates, it's because you are passing a wrong function to be assigned to a function pointer. Take this class for example.
class X
{
public:
static void Y(bool x)
{
}
};Now if the function pointer is typedeffed to
typedef void (*Func)(bool x);
, you can doFunc f = &X::Y;
. However, if the function pointer is typedeffed totypedef void (*X::Func)(bool x);
, you can't doFunc f = &X::Y;
. That's because X::Func implies that the first (or last) parameter of the function pointed to by Func is the "this" pointer (thiscall calling convention). Because static functions don't take the "this" pointer as a parameter, the compiler will rejectFunc f = &X::Y;
. The solution is to remove the static modifier from Y, or, change the typedef by removing the X:: prefix. Regards Senthil _____________________________ My Blog | My Articles | WinMacroS. Senthil Kumar wrote:
The solution is to remove the static modifier from Y, or, change the typedef by removing the X:: prefix.
Hai Senthil, Thanks for your time... I have found the solution, my friend soon post the code here !
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV -- modified at 1:47 Friday 23rd December, 2005
-
I don't get it. Are you saying you want to solve the problem without changing the function pointer signature and the static modifier? The problem you have is not in any way related to templates, it's because you are passing a wrong function to be assigned to a function pointer. Take this class for example.
class X
{
public:
static void Y(bool x)
{
}
};Now if the function pointer is typedeffed to
typedef void (*Func)(bool x);
, you can doFunc f = &X::Y;
. However, if the function pointer is typedeffed totypedef void (*X::Func)(bool x);
, you can't doFunc f = &X::Y;
. That's because X::Func implies that the first (or last) parameter of the function pointed to by Func is the "this" pointer (thiscall calling convention). Because static functions don't take the "this" pointer as a parameter, the compiler will rejectFunc f = &X::Y;
. The solution is to remove the static modifier from Y, or, change the typedef by removing the X:: prefix. Regards Senthil _____________________________ My Blog | My Articles | WinMacrohere is the solution :- #include #include using namespace std; typedef int wxCoord; typedef string wxString; template class CTextDropTarget { private: typedef bool (T::*pt2Func)(wxCoord, wxCoord, const wxString&); T* m_pParent; pt2Func m_pt2CallbackFunc; public: CTextDropTarget(T* pParent, pt2Func pt2CallbackFunc); virtual ~CTextDropTarget(void); virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& data); }; template CTextDropTarget::CTextDropTarget(T* pParent, pt2Func pt2CallbackFunc) : m_pParent(pParent) , m_pt2CallbackFunc(pt2CallbackFunc) {} template CTextDropTarget::~CTextDropTarget(void) {} template bool CTextDropTarget::OnDropText(wxCoord x, wxCoord y, const wxString& data) { return (m_pParent->*m_pt2CallbackFunc)(x, y, data); } class CMyListCtrl { private: CTextDropTarget *m_pDropTarget; public: CMyListCtrl() { m_pDropTarget = new CTextDropTarget< CMyListCtrl >(this, CMyListCtrl::OnTextDropTarget); } bool OnTextDropTarget(wxCoord x, wxCoord y, const wxString& data) { std::cout << data; return true; } }; void main() { CMyListCtrl a; }
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
a question from ALOK??? :~, that should be a real question.:)
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho
--[V]--
VivekuniQ wrote:
that should be a real question.
and real answer :- http://www.codeproject.com/script/comments/forums.asp?msg=1315456&forumid=1647#xx1315456xx[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV