-
September 23rd, 2003, 03:59 AM
#1
What is the Best Way ?
Assume that a dialog Box has a Edit Control.
To access the edit control we should define a member variable. What is the best way of definning Member variable ?
Code:
CEdit* m_pedtName; // Pointer
OR
or anythin else ?
What is most suitable if Dialog box has lot of controls ?
-
September 23rd, 2003, 04:03 AM
#2
Simply use the second one...
-
September 23rd, 2003, 04:05 AM
#3
Please tell me the reason?
Originally posted by Andreas Masur
Simply use the second one...
Please Tell me the reason ?
isn't there any difference of memory consumption?
Thank you,
Bye
-
September 23rd, 2003, 04:11 AM
#4
That depends : if those controls appear (instanciate) only in some cases, probably it is useful to declare them as pointers; otherwise, it is the same. Only you should be very carefull to release memory in pointer case.
Snakekaa
Move like a snake, think like a snake, be a snake !!!
-
September 23rd, 2003, 04:17 AM
#5
Re: Please tell me the reason?
Originally posted by dineshns
Please Tell me the reason ?
isn't there any difference of memory consumption?
Well...usig pointers always introduce the possibility of memory leaks, invalid addreses and such. There is basically no need to use them for the controls...
There might be really rare cases where you would use a pointer to controls for a good reasons in my eyes. Besides that, if you assign these member variables via the class wizard....then you only have one choice anyway...
-
September 23rd, 2003, 04:26 AM
#6
Hi,
I think you need to use pointers if you have a custom control for which you want to call a user defined (non-default) constructor. Then I only know how to do this using new...
If smne knows how to solve the problem without the use of pointers please tell me.
Extreme situations require extreme measures
-
October 28th, 2003, 12:38 PM
#7
Ok, I finally found a way that covers some cases:
Quotting from "The C++ Programming Language" (Stroustrup)
10.4.6.1 Necessary member Initialization
Member initializers are essential for types for which initialization differs from assignement - that is, for member objects of classes without default constructors, for const members, and for reference members...
Extreme situations require extreme measures
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|