Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Linker problem

Linker problem

Scheduled Pinned Locked Moved C / C++ / MFC
comhelpdiscussion
18 Posts 6 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D David Crow

    ThatsAlok wrote:

    D:\Alok\Test Project\cpp\11.cpp(70)

    I don't see 70 lines in your code snippet. :confused:


    "Take only what you need and leave the land as you found it." - Native American Proverb

    T Offline
    T Offline
    ThatsAlok
    wrote on last edited by
    #5

    DavidCrow wrote:

    I don't see 70 lines in your code snippet.

    Hai Sir, while posting code.. I removed blank lines from source code.. actually problem is at this line :-

    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

    1 Reply Last reply
    0
    • T ThatsAlok

      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

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #6

      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]

      T C 2 Replies Last reply
      0
      • T toxcct

        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]

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #7

        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

        1 Reply Last reply
        0
        • T toxcct

          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]

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #8

          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.

          1 Reply Last reply
          0
          • T ThatsAlok

            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

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #9

            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).

            T 1 Reply Last reply
            0
            • T ThatsAlok

              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

              E Offline
              E Offline
              Eytukan
              wrote on last edited by
              #10

              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]--

              T 2 Replies Last reply
              0
              • T ThatsAlok

                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

                S Offline
                S Offline
                S Senthil Kumar
                wrote on last edited by
                #11

                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

                T 1 Reply Last reply
                0
                • S S Senthil Kumar

                  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

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #12

                  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

                  S 1 Reply Last reply
                  0
                  • C Cedric Moonen

                    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).

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #13

                    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

                    1 Reply Last reply
                    0
                    • T ThatsAlok

                      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

                      S Offline
                      S Offline
                      S Senthil Kumar
                      wrote on last edited by
                      #14

                      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 do Func f = &X::Y;. However, if the function pointer is typedeffed to typedef void (*X::Func)(bool x);, you can't do Func 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 reject Func 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

                      T 2 Replies Last reply
                      0
                      • E Eytukan

                        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]--

                        T Offline
                        T Offline
                        ThatsAlok
                        wrote on last edited by
                        #15

                        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

                        1 Reply Last reply
                        0
                        • S S Senthil Kumar

                          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 do Func f = &X::Y;. However, if the function pointer is typedeffed to typedef void (*X::Func)(bool x);, you can't do Func 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 reject Func 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

                          T Offline
                          T Offline
                          ThatsAlok
                          wrote on last edited by
                          #16

                          S. 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

                          1 Reply Last reply
                          0
                          • S S Senthil Kumar

                            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 do Func f = &X::Y;. However, if the function pointer is typedeffed to typedef void (*X::Func)(bool x);, you can't do Func 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 reject Func 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

                            T Offline
                            T Offline
                            ThatsAlok
                            wrote on last edited by
                            #17

                            here 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

                            1 Reply Last reply
                            0
                            • E Eytukan

                              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]--

                              T Offline
                              T Offline
                              ThatsAlok
                              wrote on last edited by
                              #18

                              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

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups