Question on CEvent
-
(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
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)
-
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
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? }
-
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? }
-
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
Ok that solves my problem, thanks :) A new learning for the day
-
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
thats solves my problem thanx :)
-
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)
that doesnt work i have tried that
-
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
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 callingnew
. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible. -
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 callingnew
. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.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
-
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
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.
-
that doesnt work i have tried that
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)
-
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)
Yup i did that it gives some error
-
Yup i did that it gives some error
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)
-
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)
I have already got the asnwer to my problem from magnus & time doesnt permit me to do ne more on it
-
I have already got the asnwer to my problem from magnus & time doesnt permit me to do ne more on it
: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)
-
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
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 ); ---