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