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. Declaration of CSemaphore fails

Declaration of CSemaphore fails

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
7 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.
  • B Offline
    B Offline
    BuckBrown
    wrote on last edited by
    #1

    Good Morning Everyone, I am using Visual C++ 6.0 MFC. I am writing my first multi-threaded application and I need to be able to use semaphores. In examples that I have looked at they say to declare the semaphore class as CSemaphore cph(1, 2) for example. When I try to declare the semaphore in my class header file the compiler returns with the type of error that you would get if you did not #include a needed header file. Is there a header file that CSemaphore requires to be #included? Thanks, Buck:confused:

    L 1 Reply Last reply
    0
    • B BuckBrown

      Good Morning Everyone, I am using Visual C++ 6.0 MFC. I am writing my first multi-threaded application and I need to be able to use semaphores. In examples that I have looked at they say to declare the semaphore class as CSemaphore cph(1, 2) for example. When I try to declare the semaphore in my class header file the compiler returns with the type of error that you would get if you did not #include a needed header file. Is there a header file that CSemaphore requires to be #included? Thanks, Buck:confused:

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      BuckBrown wrote:

      Is there a header file that CSemaphore requires to be #included?

      They hide that information in the documentation[^]

      led mike

      B 1 Reply Last reply
      0
      • L led mike

        BuckBrown wrote:

        Is there a header file that CSemaphore requires to be #included?

        They hide that information in the documentation[^]

        led mike

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

        I guess I really don't understand. I read this documentation earlier and thought the idea was something like this - class CTests : public CWnd { // Construction public: CTests(); CTemperature* pTemperature; COutput* pOutput; CGPIB* pGPIB; CTabPageSSL* pTabPage; CSemaphore cph(1, 5); // Attributes private: If I remark out the declaration it compiles fine, if not it does not compile. Buck

        L Z 2 Replies Last reply
        0
        • B BuckBrown

          I guess I really don't understand. I read this documentation earlier and thought the idea was something like this - class CTests : public CWnd { // Construction public: CTests(); CTemperature* pTemperature; COutput* pOutput; CGPIB* pGPIB; CTabPageSSL* pTabPage; CSemaphore cph(1, 5); // Attributes private: If I remark out the declaration it compiles fine, if not it does not compile. Buck

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          BuckBrown wrote:

          I read this documentation earlier

          maybe your definition of "reading" is different than mine. From the documentation:

          Requirements

          Header: afxmt.h

          led mike

          B 1 Reply Last reply
          0
          • B BuckBrown

            I guess I really don't understand. I read this documentation earlier and thought the idea was something like this - class CTests : public CWnd { // Construction public: CTests(); CTemperature* pTemperature; COutput* pOutput; CGPIB* pGPIB; CTabPageSSL* pTabPage; CSemaphore cph(1, 5); // Attributes private: If I remark out the declaration it compiles fine, if not it does not compile. Buck

            Z Offline
            Z Offline
            Zac Howland
            wrote on last edited by
            #5

            BuckBrown wrote:

            class CTests : public CWnd { // Construction public: CTests(); CTemperature* pTemperature; COutput* pOutput; CGPIB* pGPIB; CTabPageSSL* pTabPage; CSemaphore cph(1, 5);

            Doing that in the header file won't compile. The overloaded constructor should be invoked using the constructor of your CTests class:

            CTests::CTests() : cph(1, 5) { // do whatever else you want to in the constructor here }
            

            If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

            B 1 Reply Last reply
            0
            • L led mike

              BuckBrown wrote:

              I read this documentation earlier

              maybe your definition of "reading" is different than mine. From the documentation:

              Requirements

              Header: afxmt.h

              led mike

              B Offline
              B Offline
              BuckBrown
              wrote on last edited by
              #6

              Gee, do I feel stupid now. I was so focused on the body of the document that I didn't even notice the little requirements section. My appologies. Thanks

              1 Reply Last reply
              0
              • Z Zac Howland

                BuckBrown wrote:

                class CTests : public CWnd { // Construction public: CTests(); CTemperature* pTemperature; COutput* pOutput; CGPIB* pGPIB; CTabPageSSL* pTabPage; CSemaphore cph(1, 5);

                Doing that in the header file won't compile. The overloaded constructor should be invoked using the constructor of your CTests class:

                CTests::CTests() : cph(1, 5) { // do whatever else you want to in the constructor here }
                

                If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                B Offline
                B Offline
                BuckBrown
                wrote on last edited by
                #7

                Boy that's the truth. That's why I became a microelectronics engineer in the integrated circuit industry (I help develop the silicon that makes us feel stupid). Thanks for the input Buck

                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