CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2003
    Location
    Sri Lanka
    Posts
    64

    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

    Code:
    CEdit m_edtName;
    or anythin else ?

    What is most suitable if Dialog box has lot of controls ?

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Simply use the second one...

  3. #3
    Join Date
    Sep 2003
    Location
    Sri Lanka
    Posts
    64

    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

  4. #4
    Join Date
    May 2002
    Location
    Romania
    Posts
    929
    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 !!!

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    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...

  6. #6
    Join Date
    Apr 2003
    Location
    Athens, Greece
    Posts
    1,094
    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

  7. #7
    Join Date
    Apr 2003
    Location
    Athens, Greece
    Posts
    1,094
    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
  •  





Click Here to Expand Forum to Full Width

Featured