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. Error with dynamic_cast

Error with dynamic_cast

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 Posts 3 Posters 0 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.
  • M Offline
    M Offline
    msr_codeproject
    wrote on last edited by
    #1

    class Filter;

    typedef void (Filter::*PFN)();

    class Filter
    {
    public:
    void ProcessPart();
    void MyProcessPart();

    struct Pair\_t
    {
    	Pair\_t(int d, PFN n) : iid(d), pfn(n) {}
    
    	int  iid;
    	PFN  pfn;
    
    private:
    
    	Pair\_t& operator=(const Pair\_t&);
    };
    

    };

    void Filter::ProcessPart()
    {
    PFN pfn2;

        //Here I am getting error C2681
    pfn2 = dynamic\_cast (&Filter::ProcessPart);
    
    Pair\_t(9, pfn2);
    

    }

    int _tmain(int argc, _TCHAR* argv[])
    {
    return 0;
    }

    I am not able to solve this. Any help? Thanks

    L I 3 Replies Last reply
    0
    • M msr_codeproject

      class Filter;

      typedef void (Filter::*PFN)();

      class Filter
      {
      public:
      void ProcessPart();
      void MyProcessPart();

      struct Pair\_t
      {
      	Pair\_t(int d, PFN n) : iid(d), pfn(n) {}
      
      	int  iid;
      	PFN  pfn;
      
      private:
      
      	Pair\_t& operator=(const Pair\_t&);
      };
      

      };

      void Filter::ProcessPart()
      {
      PFN pfn2;

          //Here I am getting error C2681
      pfn2 = dynamic\_cast (&Filter::ProcessPart);
      
      Pair\_t(9, pfn2);
      

      }

      int _tmain(int argc, _TCHAR* argv[])
      {
      return 0;
      }

      I am not able to solve this. Any help? Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You are trying to cast a function address to a pointer to a class, which is illegal.

      speaking as ...

      M 1 Reply Last reply
      0
      • L Lost User

        You are trying to cast a function address to a pointer to a class, which is illegal.

        speaking as ...

        M Offline
        M Offline
        msr_codeproject
        wrote on last edited by
        #3

        Ya I got it. Thanks Richard MacCutchan

        1 Reply Last reply
        0
        • M msr_codeproject

          class Filter;

          typedef void (Filter::*PFN)();

          class Filter
          {
          public:
          void ProcessPart();
          void MyProcessPart();

          struct Pair\_t
          {
          	Pair\_t(int d, PFN n) : iid(d), pfn(n) {}
          
          	int  iid;
          	PFN  pfn;
          
          private:
          
          	Pair\_t& operator=(const Pair\_t&);
          };
          

          };

          void Filter::ProcessPart()
          {
          PFN pfn2;

              //Here I am getting error C2681
          pfn2 = dynamic\_cast (&Filter::ProcessPart);
          
          Pair\_t(9, pfn2);
          

          }

          int _tmain(int argc, _TCHAR* argv[])
          {
          return 0;
          }

          I am not able to solve this. Any help? Thanks

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Function pointer casting has a really crappy syntax in C. I posted on it way back, but so ugly is I have totally forgotten how it goes.

          ============================== Nothing to say.

          1 Reply Last reply
          0
          • M msr_codeproject

            class Filter;

            typedef void (Filter::*PFN)();

            class Filter
            {
            public:
            void ProcessPart();
            void MyProcessPart();

            struct Pair\_t
            {
            	Pair\_t(int d, PFN n) : iid(d), pfn(n) {}
            
            	int  iid;
            	PFN  pfn;
            
            private:
            
            	Pair\_t& operator=(const Pair\_t&);
            };
            

            };

            void Filter::ProcessPart()
            {
            PFN pfn2;

                //Here I am getting error C2681
            pfn2 = dynamic\_cast (&Filter::ProcessPart);
            
            Pair\_t(9, pfn2);
            

            }

            int _tmain(int argc, _TCHAR* argv[])
            {
            return 0;
            }

            I am not able to solve this. Any help? Thanks

            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #5

            You've already had help from the clever people here, but it would have helped them if you'd put the error in the posting too. If you make it easy to help you, more people will try. Iain.

            I am one of "those foreigners coming over here and stealing our jobs". Yay me!

            L 1 Reply Last reply
            0
            • I Iain Clarke Warrior Programmer

              You've already had help from the clever people here, but it would have helped them if you'd put the error in the posting too. If you make it easy to help you, more people will try. Iain.

              I am one of "those foreigners coming over here and stealing our jobs". Yay me!

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Iain Clarke, Warrior Programmer wrote:

              if you'd put the error in the posting too.

              Ahem, it's in the original question, as a C++ comment.

              speaking as ...

              I 1 Reply Last reply
              0
              • L Lost User

                Iain Clarke, Warrior Programmer wrote:

                if you'd put the error in the posting too.

                Ahem, it's in the original question, as a C++ comment.

                speaking as ...

                I Offline
                I Offline
                Iain Clarke Warrior Programmer
                wrote on last edited by
                #7

                OK, I'll partially let him off then! But pasting the whole error message is still wise. Do *you* remember E1234 off by heart? Iain.

                I am one of "those foreigners coming over here and stealing our jobs". Yay me!

                L 1 Reply Last reply
                0
                • I Iain Clarke Warrior Programmer

                  OK, I'll partially let him off then! But pasting the whole error message is still wise. Do *you* remember E1234 off by heart? Iain.

                  I am one of "those foreigners coming over here and stealing our jobs". Yay me!

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Iain Clarke, Warrior Programmer wrote:

                  But pasting the whole error message is still wise.

                  I agree entirely.

                  Iain Clarke, Warrior Programmer wrote:

                  Do *you* remember E1234 off by heart?

                  No, but I can spell MSDN and even Google. ;)

                  speaking as ...

                  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