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. A Thready Question

A Thready Question

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
10 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.
  • X Offline
    X Offline
    Xavier Shay
    wrote on last edited by
    #1

    I've been recently experimenting with threads and found that I got an error when i tried to pass a class member function as the Thread entry point (something about not converting void(void *) to void(__cdcl)(void *). I tried attaching the __cdcl (somethin like __cdcl anyway) to the function definition but it did not help. Is this possible and if not is there a way to have global functions access member variables (friend keyword??)? - X

    N M D 3 Replies Last reply
    0
    • X Xavier Shay

      I've been recently experimenting with threads and found that I got an error when i tried to pass a class member function as the Thread entry point (something about not converting void(void *) to void(__cdcl)(void *). I tried attaching the __cdcl (somethin like __cdcl anyway) to the function definition but it did not help. Is this possible and if not is there a way to have global functions access member variables (friend keyword??)? - X

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      You cannot pass non-static functions as the thread proc. But what you can do is to pass a pointer to your class's instance as the LPVOID parameter Then you can cast the pointer to your class and use the members from the global function. Nish

      X 1 Reply Last reply
      0
      • N Nish Nishant

        You cannot pass non-static functions as the thread proc. But what you can do is to pass a pointer to your class's instance as the LPVOID parameter Then you can cast the pointer to your class and use the members from the global function. Nish

        X Offline
        X Offline
        Xavier Shay
        wrote on last edited by
        #3

        Thankyou greatly. A reply in 6 minutes. Who would have thought?? - X

        N 1 Reply Last reply
        0
        • X Xavier Shay

          Thankyou greatly. A reply in 6 minutes. Who would have thought?? - X

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          That's Code Project for you :-) Nish

          1 Reply Last reply
          0
          • X Xavier Shay

            I've been recently experimenting with threads and found that I got an error when i tried to pass a class member function as the Thread entry point (something about not converting void(void *) to void(__cdcl)(void *). I tried attaching the __cdcl (somethin like __cdcl anyway) to the function definition but it did not help. Is this possible and if not is there a way to have global functions access member variables (friend keyword??)? - X

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            See the VC forum FAQ. :) --Mike-- http://home.inreach.com/mdunn/ If there's something strange / in your VC code / Who you gonna call? / Ghostbusters! :love: your :bob: with :vegemite: and :beer:

            1 Reply Last reply
            0
            • X Xavier Shay

              I've been recently experimenting with threads and found that I got an error when i tried to pass a class member function as the Thread entry point (something about not converting void(void *) to void(__cdcl)(void *). I tried attaching the __cdcl (somethin like __cdcl anyway) to the function definition but it did not help. Is this possible and if not is there a way to have global functions access member variables (friend keyword??)? - X

              D Offline
              D Offline
              Deepak Khajuria
              wrote on last edited by
              #6

              You can make the function as Static member of the class(instead of global class) and then pass it to thread function. Deepak Khajuria

              N 1 Reply Last reply
              0
              • D Deepak Khajuria

                You can make the function as Static member of the class(instead of global class) and then pass it to thread function. Deepak Khajuria

                N Offline
                N Offline
                Nish Nishant
                wrote on last edited by
                #7

                But then he wont be able to access the non-static members Nish

                D 1 Reply Last reply
                0
                • N Nish Nishant

                  But then he wont be able to access the non-static members Nish

                  D Offline
                  D Offline
                  Deepak Khajuria
                  wrote on last edited by
                  #8

                  Yes, he has to pass the instance of the class as parameter,or something similar. But the main difference is that the static function of the class has full access to the class, where as global function cannot access the protected/private members. Deepak Khajuria

                  N 1 Reply Last reply
                  0
                  • D Deepak Khajuria

                    Yes, he has to pass the instance of the class as parameter,or something similar. But the main difference is that the static function of the class has full access to the class, where as global function cannot access the protected/private members. Deepak Khajuria

                    N Offline
                    N Offline
                    Nish Nishant
                    wrote on last edited by
                    #9

                    He can always call the static functions of his class from his global function anyway. Thus he can also access all static members (via the static function, of course) Nish

                    D 1 Reply Last reply
                    0
                    • N Nish Nishant

                      He can always call the static functions of his class from his global function anyway. Thus he can also access all static members (via the static function, of course) Nish

                      D Offline
                      D Offline
                      Deepak Khajuria
                      wrote on last edited by
                      #10

                      The static functions & global functions are same in sense that you do have instance of the class(this) in it. You need to get instance of the class from somewhere to call its non-static members. But the main difference is that the static function of the class has access to the protected/private members of the object of same class. This does not hold true for the global functions.(unless you make them friend) So in a thread where you require direct access to class protected/private members, it is better to make thread function as static member of the class. Deepak Khajuria

                      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