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. Function Pointer

Function Pointer

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structureshelptutorial
5 Posts 4 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.
  • B Offline
    B Offline
    baerten
    wrote on last edited by
    #1

    I like to create a functionpointer on an instance of an object. I have a Universal-List that uses an array of pointer to different Rows. A row has a basic-class and all specific rows ( for example customers ) are derivated from this Class. Row -> CustomerRow In the Universal-List i like to create an array of pointer to the member-functions of the rows. The row exists already as an instance and i like to assign the functionpointer to the memberfonction of this instance... Is it possible? MSDN Help says that functionpointer must point to static functions. But in an instance, the function is precised and accessible, so why does the fctpointer don't save the "linkage" Thanks

    C A 2 Replies Last reply
    0
    • B baerten

      I like to create a functionpointer on an instance of an object. I have a Universal-List that uses an array of pointer to different Rows. A row has a basic-class and all specific rows ( for example customers ) are derivated from this Class. Row -> CustomerRow In the Universal-List i like to create an array of pointer to the member-functions of the rows. The row exists already as an instance and i like to assign the functionpointer to the memberfonction of this instance... Is it possible? MSDN Help says that functionpointer must point to static functions. But in an instance, the function is precised and accessible, so why does the fctpointer don't save the "linkage" Thanks

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

      baerten wrote:

      But in an instance, the function is precised and accessible, so why does the fctpointer don't save the "linkage"

      Because with a member function, there is an explicit parameter that is passed to your function: the this parameter (pointer to the instance of the class). If you post some code, maybe we can help you. Basically, what you need to do is specify that the functions in your list are members of your class (by addind a CMyClass:: in front). But without seeing code, it is difficult.


      Cédric Moonen Software developer
      Charting control [Updated - v1.1]

      B 1 Reply Last reply
      0
      • C Cedric Moonen

        baerten wrote:

        But in an instance, the function is precised and accessible, so why does the fctpointer don't save the "linkage"

        Because with a member function, there is an explicit parameter that is passed to your function: the this parameter (pointer to the instance of the class). If you post some code, maybe we can help you. Basically, what you need to do is specify that the functions in your list are members of your class (by addind a CMyClass:: in front). But without seeing code, it is difficult.


        Cédric Moonen Software developer
        Charting control [Updated - v1.1]

        B Offline
        B Offline
        baerten
        wrote on last edited by
        #3

        void RTB::Config_Customer() { // Creates X Elements in the Internal List InternList = (BasicRow**)malloc(NumberofRows*sizeof(BasicRow*)); for(int i=0; i( ActFillRow ); // ActFillRow is a BasicRow-pointer // Creates the 8 Meta-Data Elements MetaTable= (MetaInfo*)malloc(8*sizeof( MetaInfo)); MetaTable[0].Name = "Name"; MetaTable[0].Func = &CustomerRow::SetName; // The pointer to the function that Sets the Name to the column "Name" MetaTable[1].Name = "Firstname"; MetaTable[1].Func = &CustomerRow::SetFirstname; } The MetaTable : typedef struct MetaInfoForColumns { CString Name; ColumnSetter Func; } MetaInfo; Column Setter: typedef void (CustomerRow::*ColumnSetter)(CString); // Functionspointer Thanks a lot

        M 1 Reply Last reply
        0
        • B baerten

          I like to create a functionpointer on an instance of an object. I have a Universal-List that uses an array of pointer to different Rows. A row has a basic-class and all specific rows ( for example customers ) are derivated from this Class. Row -> CustomerRow In the Universal-List i like to create an array of pointer to the member-functions of the rows. The row exists already as an instance and i like to assign the functionpointer to the memberfonction of this instance... Is it possible? MSDN Help says that functionpointer must point to static functions. But in an instance, the function is precised and accessible, so why does the fctpointer don't save the "linkage" Thanks

          A Offline
          A Offline
          Anonymuos
          wrote on last edited by
          #4

          baerten wrote:

          I like to create a functionpointer on an instance of an object.

          Try: http://www.parashift.com/c++-faq-lite/pointers-to-members.html[^]

          1 Reply Last reply
          0
          • B baerten

            void RTB::Config_Customer() { // Creates X Elements in the Internal List InternList = (BasicRow**)malloc(NumberofRows*sizeof(BasicRow*)); for(int i=0; i( ActFillRow ); // ActFillRow is a BasicRow-pointer // Creates the 8 Meta-Data Elements MetaTable= (MetaInfo*)malloc(8*sizeof( MetaInfo)); MetaTable[0].Name = "Name"; MetaTable[0].Func = &CustomerRow::SetName; // The pointer to the function that Sets the Name to the column "Name" MetaTable[1].Name = "Firstname"; MetaTable[1].Func = &CustomerRow::SetFirstname; } The MetaTable : typedef struct MetaInfoForColumns { CString Name; ColumnSetter Func; } MetaInfo; Column Setter: typedef void (CustomerRow::*ColumnSetter)(CString); // Functionspointer Thanks a lot

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            You're going to need a CustomerRow object to make the call to MetaTable[].Func if the function is a non-static member variable. If you make the columnsetter functions static they are going to need a CustomerRow object to access any non-static CustomerRow members. You could pass a CustomerRow reference/pointer to the function that uses the metatable to dispatch to the corresponding column setter function. Without seeing how you are using the metatable I can't give you a code example :) Mark

            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