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.
  • P Prakash Nadar

    CEvent( BOOL bInitiallyOwn = FALSE, BOOL bManualReset = FALSE, LPCTSTR lpszName = NULL, LPSECURITY_ATTRIBUTES lpsaAttribute = NULL ); this is the construtor of the CEvent , all are optional constructor, you need to set it the way you want it, 2nd parameter will be of some interest to you. regards, Prakash.


    "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
    #4

    (Well i found answer to my first question it is automatic) Agreed that the constructor helps me specify the same but how do i use the constructor in creating my object. Ok lets put it this way class A { CEvent e; } now how do i create e with the constructor. I hope u r getting my problem

    P 2 Replies Last reply
    0
    • D DimpleSurana

      (Well i found answer to my first question it is automatic) Agreed that the constructor helps me specify the same but how do i use the constructor in creating my object. Ok lets put it this way class A { CEvent e; } now how do i create e with the constructor. I hope u r getting my problem

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

      class A{
      {
      CEvent e(TRUE,TRUE,NULL,NULL);
      }

      this creats a event that is initialy owned, manual reset, unnamed event, null security. Hope i cleared ur problem.


      "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

        class A{
        {
        CEvent e(TRUE,TRUE,NULL,NULL);
        }

        this creats a event that is initialy owned, manual reset, unnamed event, null security. Hope i cleared ur problem.


        "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
        #6

        It gives syntax error on compilation

        _ 1 Reply Last reply
        0
        • D DimpleSurana

          It gives syntax error on compilation

          _ Offline
          _ Offline
          _Magnus_
          wrote on last edited by
          #7
          Class A
          {
             CEvent e;
          
             A() : e(NULL,NULL,NULL)
             {
             }
          };
          

          /Magnus


          - I don't necessarily agree with everything I say

          D 1 Reply Last reply
          0
          • _ _Magnus_
            Class A
            {
               CEvent e;
            
               A() : e(NULL,NULL,NULL)
               {
               }
            };
            

            /Magnus


            - I don't necessarily agree with everything I say

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

            hmm thats a inline definition... i dont wanna create my class object in that fashion & neither does that compile. My class A has its own constructor

            _ 1 Reply Last reply
            0
            • D DimpleSurana

              hmm thats a inline definition... i dont wanna create my class object in that fashion & neither does that compile. My class A has its own constructor

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

              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 1 Reply Last reply
              0
              • D DimpleSurana

                (Well i found answer to my first question it is automatic) Agreed that the constructor helps me specify the same but how do i use the constructor in creating my object. Ok lets put it this way class A { CEvent e; } now how do i create e with the constructor. I hope u r getting my problem

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

                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 1 Reply Last reply
                0
                • _ _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
                                          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