I've only recently started to learn Windows programming using VC++.
It's relatively easy to understand the basics fo attaching functions
to controls but I've been trying to learn Windows from the roots on
down. In looking at source code I'm finding a tendency for some
programmers to declare an object of their application type with a new
and subsequently use the pointer-member-of operator to access the
members of the class object. Considering it was obvious in these
instances that there was only going to be one application object, what
is the point of declaring a pointer and then go through the process of
allocating the object itself rather than simply declaring the object
and forgetting the allocation?
--
Lilith 10 1198
Lilith wrote: I've only recently started to learn Windows programming using VC++.
Sample VC++ code is about the most wretched style you can find. The only
thing worse in our industry is Dr Dobb's Journal.
...In looking at source code I'm finding a tendency for some programmers to declare an object of their application type with a new and subsequently use the pointer-member-of operator to access the members of the class object.
You just mean -> notation. Not pointer to member.
But, yes, these programmers are using 'new' because "all the other
programmers were doing it", not because they need an object to live longer
than the current scope.
Read books like /Design Patterns/ and /Effective C++/ to learn good style.
--
Phlip http://www.c2.com/cgi/wiki?ZeekLand
> I've only recently started to learn Windows programming using VC++. It's relatively easy to understand the basics fo attaching functions to controls but I've been trying to learn Windows from the roots on down.
This has nothing to do with the C++ language.
In looking at source code I'm finding a tendency for some programmers to declare an object of their application type with a new and subsequently use the pointer-member-of operator to access the members of the class object. Considering it was obvious in these instances that there was only going to be one application object, what is the point of declaring a pointer and then go through the process of allocating the object itself rather than simply declaring the object and forgetting the allocation?
I'm not exactly sure what your question is, but it sounds like you're
asking "what the difference between creating an object with new and
just declaring it as an automatic variable?" If that's what you're
asking, new creates memory on the heap, declaring an automatic variable
puts the object on the stack. Another difference is that with a
pointer to an object created with new, you can use polymorphism.
-- Lilith
Lilith wrote: I've only recently started to learn Windows programming using VC++. It's relatively easy to understand the basics fo attaching functions to controls but I've been trying to learn Windows from the roots on down. In looking at source code I'm finding a tendency for some programmers to declare an object of their application type with a new and subsequently use the pointer-member-of operator to access the members of the class object.
You mean -> operator, yes?
Considering it was obvious in these instances that there was only going to be one application object, what is the point of declaring a pointer and then go through the process of allocating the object itself rather than simply declaring the object and forgetting the allocation?
The difference is where the object is allocated and _when_ it is
initialised. Statically allocated objects (objects with static storage
duration) are allocated potentially in a different place than those with
dynamic storage duration. Also, you may need to have control over the
time when your application object is initialised. Statically allocated
objects are initialised at some point before the 'main' function is
called, which is not necessarily the right time.
V
BigBrian wrote: new creates memory on the heap, declaring an automatic variable puts the object on the stack. Another difference is that with a pointer to an object created with new, you can use polymorphism.
You can use polymorphism with a pointer to an object on the stack as well.
DW
On 5 Jul 2005 14:58:16 -0700, "BigBrian" <wo**@brianmielke.com> wrote: I've only recently started to learn Windows programming using VC++. It's relatively easy to understand the basics fo attaching functions to controls but I've been trying to learn Windows from the roots on down.
This has nothing to do with the C++ language.
No, it was by way of a small introduction and an explanation of where
I'm coming from.
In looking at source code I'm finding a tendency for some programmers to declare an object of their application type with a new and subsequently use the pointer-member-of operator to access the members of the class object. Considering it was obvious in these instances that there was only going to be one application object, what is the point of declaring a pointer and then go through the process of allocating the object itself rather than simply declaring the object and forgetting the allocation?
I'm not exactly sure what your question is, but it sounds like you're asking "what the difference between creating an object with new and just declaring it as an automatic variable?" If that's what you're asking, new creates memory on the heap, declaring an automatic variable puts the object on the stack. Another difference is that with a pointer to an object created with new, you can use polymorphism.
No, I know the difference as regards to their creation. I was more
interested in the why of it in a particular instance. I didn't see
the purpose of creating the object dynamically when a statically
declared variable would have sufficed. I was also curious as to
whether or not there is a small impact on performance in using -> to
reference the members of the object.
--
Lilith
On Tue, 05 Jul 2005 21:55:57 GMT, "Phlip" <ph*******@yahoo.com> wrote: Lilith wrote:
I've only recently started to learn Windows programming using VC++.
Sample VC++ code is about the most wretched style you can find. The only thing worse in our industry is Dr Dobb's Journal.
So, my earlier issues aren't going to bring much on eBay? Seriously,
it was Dr Dobbs that got me over my impass at understanding C in the
first place.
...In looking at source code I'm finding a tendency for some programmers to declare an object of their application type with a new and subsequently use the pointer-member-of operator to access the members of the class object.
You just mean -> notation. Not pointer to member.
Yes. I'm inclined to try to be concise in my wording and it sometimes
works against me.
But, yes, these programmers are using 'new' because "all the other programmers were doing it", not because they need an object to live longer than the current scope.
Someone had to start it. :-) I see little reason for declaring a
single object dynamically but I can see the need for doing it for
arrays and as part of a linked list. But I'm not the expert
programmer that many on this are and wanted to make sure I'm not
missing a bet somewhere.
Read books like /Design Patterns/ and /Effective C++/ to learn good style.
--
Lilith
On Tue, 05 Jul 2005 17:57:14 -0400, Victor Bazarov
<v.********@comAcast.net> wrote: Lilith wrote: I've only recently started to learn Windows programming using VC++. It's relatively easy to understand the basics fo attaching functions to controls but I've been trying to learn Windows from the roots on down. In looking at source code I'm finding a tendency for some programmers to declare an object of their application type with a new and subsequently use the pointer-member-of operator to access the members of the class object.
You mean -> operator, yes?
Considering it was obvious in these instances that there was only going to be one application object, what is the point of declaring a pointer and then go through the process of allocating the object itself rather than simply declaring the object and forgetting the allocation?
The difference is where the object is allocated and _when_ it is initialised. Statically allocated objects (objects with static storage duration) are allocated potentially in a different place than those with dynamic storage duration. Also, you may need to have control over the time when your application object is initialised. Statically allocated objects are initialised at some point before the 'main' function is called, which is not necessarily the right time.
Many thanks,
Lilith
Lilith wrote: No, it was by way of a small introduction and an explanation of where I'm coming from.
Sorry. You mentioned "Windows" too high in your post. Knees jerked. We'll
try not to do it again.
--
Phlip http://www.c2.com/cgi/wiki?ZeekLand
* Lilith: In looking at source code I'm finding a tendency for some programmers to declare an object of their application type with a new and subsequently use the pointer-member-of operator to access the members of the class object. Considering it was obvious in these instances that there was only going to be one application object, what is the point of declaring a pointer and then go through the process of allocating the object itself rather than simply declaring the object and forgetting the allocation?
Difficult to say without a concrete example, but one reason might be that
the single object is of a class that's derived from a class A that is
designed for dynamic allocation, e.g. an A-object will self-destroy when
a given "we're finished" message is processed. But that is speculation.
I've programmed extensively on the platform you mentioned and can not recall
ever needing to dynamically allocate an application object (window objects,
on the other hand...).
Perhaps Phlip's answer is the most likely, that they're doing this because
they see other programmers doing it (in various situations), and don't
understand the reasons but just copy what they think others do.
That's very common in general.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
On Wed, 06 Jul 2005 01:49:30 GMT, "Phlip" <ph*******@yahoo.com> wrote: Lilith wrote:
No, it was by way of a small introduction and an explanation of where I'm coming from.
Sorry. You mentioned "Windows" too high in your post. Knees jerked. We'll try not to do it again.
And I was aware that that could happen. But I anticipated that the
practice I was questioning might be a necessity of the environment I
was programming for or at least a convenience.
--
Lilith This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lawrence |
last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in
IE???
<SCRIPT type='text/javascript'>
function makeVisible(nameOfDiv) {...
|
by: Roy |
last post by:
Hey all. All I'm trying to do is get a darn double solid bar in my
datagrid footer. Doesn't seem to work. Any tips?
The weird thing is all the other stylesheet attributes work. If I
increase the...
|
by: cedoucette |
last post by:
I just wrote code to support sortable columns in a datagrid.
It seems to work fine; but, it doesn't look right.
The problem is that I have a generic style for links
and a different style for the...
|
by: RonY |
last post by:
I have a dropdown which calls SetTimePeriod method on change the selection. In the JS function, I reset the field style.display based on what the selection is. This works fine with IE but not working...
|
by: JT |
last post by:
Hi,
I have done a fair amount of style editing inline in ASP. I'm now
using VS 2005 with a standard web project (not Web Application
Project). This is my first foray into CSS in a style sheet...
|
by: rongchaua |
last post by:
Hi all,
I want to change the style of a button. But I don't know how to do it.
For example, I have already a button OK on form. I want to add these styles
to this button (WS_CHILD || WS_VISIBLE ||...
|
by: Armin Gajda |
last post by:
Hi,
I have the following problem:
An input field get a border assigned by a style class (e.g. 2px solid red).
When the field gets the focus, we set the border to green.
element.style.border...
|
by: =?Utf-8?B?QXR1bA==?= |
last post by:
When .Net 1.0 webservice (VS2003) generates a wsdl -
<wsdl:binding name="TestSoap" type="tns:TestSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document"/(note:...
|
by: Michellevt |
last post by:
Hi
I am working on a project (for college) and wondered if anyone can help me with my problem. In the project we are not allowed to make use of any "style" attributes but "class" attributes...
|
by: Claus Mygind |
last post by:
I want to move some style setting into a javaScript function so I can make them variable but I get "invalid assignment left-hand side" error?
see my question at the bottom of this message.
It...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |