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. Question on CEvent

Question on CEvent

Scheduled Pinned Locked Moved C / C++ / MFC
question
24 Posts 5 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.
  • _ _Magnus_

    That is the syntax for calling membervaribles ctors, put it in your class A's ctor. /Magnus


    - I don't necessarily agree with everything I say

    D Offline
    D Offline
    DimpleSurana
    wrote on last edited by
    #11

    This is the scenario class A { A(int,ClassB *b); CEvent e; } In the implementation file -> A::A(int,ClassB *b) { What do i put here? }

    _ 1 Reply Last reply
    0
    • D DimpleSurana

      This is the scenario class A { A(int,ClassB *b); CEvent e; } In the implementation file -> A::A(int,ClassB *b) { What do i put here? }

      _ Offline
      _ Offline
      _Magnus_
      wrote on last edited by
      #12
      A::A(int,ClassB *b) :
         e(NULL,NULL)
      {
      }
      

      The actual params to e above is wrong, pass them as you like to have them. /Magnus


      - I don't necessarily agree with everything I say

      D A 3 Replies Last reply
      0
      • _ _Magnus_
        A::A(int,ClassB *b) :
           e(NULL,NULL)
        {
        }
        

        The actual params to e above is wrong, pass them as you like to have them. /Magnus


        - I don't necessarily agree with everything I say

        D Offline
        D Offline
        DimpleSurana
        wrote on last edited by
        #13

        Ok that solves my problem, thanks :) A new learning for the day

        1 Reply Last reply
        0
        • _ _Magnus_
          A::A(int,ClassB *b) :
             e(NULL,NULL)
          {
          }
          

          The actual params to e above is wrong, pass them as you like to have them. /Magnus


          - I don't necessarily agree with everything I say

          D Offline
          D Offline
          DimpleSurana
          wrote on last edited by
          #14

          thats solves my problem thanx :)

          1 Reply Last reply
          0
          • P Prakash Nadar

            class A { A() { e = new CEvent(TRUE,TRUE,NULL,NULL); } CEvent *e; } How about this.


            "When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)

            D Offline
            D Offline
            DimpleSurana
            wrote on last edited by
            #15

            that doesnt work i have tried that

            P 1 Reply Last reply
            0
            • _ _Magnus_
              A::A(int,ClassB *b) :
                 e(NULL,NULL)
              {
              }
              

              The actual params to e above is wrong, pass them as you like to have them. /Magnus


              - I don't necessarily agree with everything I say

              A Offline
              A Offline
              Antti Keskinen
              wrote on last edited by
              #16

              I am not absolutely sure, but I believe that in this construction call, a temporary CEvent object is created, then an equality operation is used to make the _e_ equal to it, and then the temporary object is deleted. On a memory-constrict system this might cause a problem. A better way when you have members in your class that are not base types (classes or similar) and need to initialize them, is to always use a pointer to the type, and reserve memory from the heap by calling new. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

              _ 1 Reply Last reply
              0
              • A Antti Keskinen

                I am not absolutely sure, but I believe that in this construction call, a temporary CEvent object is created, then an equality operation is used to make the _e_ equal to it, and then the temporary object is deleted. On a memory-constrict system this might cause a problem. A better way when you have members in your class that are not base types (classes or similar) and need to initialize them, is to always use a pointer to the type, and reserve memory from the heap by calling new. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

                _ Offline
                _ Offline
                _Magnus_
                wrote on last edited by
                #17

                I dont think that is the case, any code in the ctor for the object would then be run twice. Also if you had pointer members allocated in the ctor and deleted in the dtor they would be pointing to garbage. /Magnus


                - I don't necessarily agree with everything I say

                A 1 Reply Last reply
                0
                • _ _Magnus_

                  I dont think that is the case, any code in the ctor for the object would then be run twice. Also if you had pointer members allocated in the ctor and deleted in the dtor they would be pointing to garbage. /Magnus


                  - I don't necessarily agree with everything I say

                  A Offline
                  A Offline
                  Antti Keskinen
                  wrote on last edited by
                  #18

                  After a quick check, the case was verified: the constructor of the member class is called only once if it is declared after the ':' on the host class's constructor. However, I prefer pointers :) -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

                  1 Reply Last reply
                  0
                  • D DimpleSurana

                    that doesnt work i have tried that

                    P Offline
                    P Offline
                    Prakash Nadar
                    wrote on last edited by
                    #19

                    Well i guess that is the easiest way to initialise anything. Any way just out of curiousity what is the compiler error you are getting. did you put the following statement. #include


                    "When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)

                    D 1 Reply Last reply
                    0
                    • P Prakash Nadar

                      Well i guess that is the easiest way to initialise anything. Any way just out of curiousity what is the compiler error you are getting. did you put the following statement. #include


                      "When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)

                      D Offline
                      D Offline
                      DimpleSurana
                      wrote on last edited by
                      #20

                      Yup i did that it gives some error

                      P 1 Reply Last reply
                      0
                      • D DimpleSurana

                        Yup i did that it gives some error

                        P Offline
                        P Offline
                        Prakash Nadar
                        wrote on last edited by
                        #21

                        You still did not specify what error you are getting perhaps that would be more helpfull.


                        "When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)

                        D 1 Reply Last reply
                        0
                        • P Prakash Nadar

                          You still did not specify what error you are getting perhaps that would be more helpfull.


                          "When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)

                          D Offline
                          D Offline
                          DimpleSurana
                          wrote on last edited by
                          #22

                          I have already got the asnwer to my problem from magnus & time doesnt permit me to do ne more on it

                          P 1 Reply Last reply
                          0
                          • D DimpleSurana

                            I have already got the asnwer to my problem from magnus & time doesnt permit me to do ne more on it

                            P Offline
                            P Offline
                            Prakash Nadar
                            wrote on last edited by
                            #23

                            :doh:Oops sorry didnt read that link... that is also a good answer.


                            "When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)

                            1 Reply Last reply
                            0
                            • D DimpleSurana

                              If i declare a CEvent object as a member of my class - a) Is it created such that it is manual reset / automatic b) If automatic how do i tell the CEvent object that it shud be manul reset Dimple

                              K Offline
                              K Offline
                              KaroCH
                              wrote on last edited by
                              #24

                              if you use CEvent you us it with the follwing constructor. so you could set bManualRest = TRUE. it doesnt care if you use it as member of your class... karo --- CEvent( BOOL bInitiallyOwn = FALSE, BOOL bManualReset = FALSE, LPCTSTR lpszName = NULL, LPSECURITY_ATTRIBUTES lpsaAttribute = NULL ); ---

                              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