473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Pointers and polymorphism explained [preview, PDF, part of my attempted "Correct C++ Tutorial"]

So, I got the itch to write something more...

I apologize for not doing more on the attempted "Correct C++ Tutorial"
earlier, but there were reasons.

This is an UNFINISHED and RAW document, and at the end there is even pure
mindstorming text left in, but already I think it can be very useful.

<url: http://home.no.net/dubjai/win32cpptut/special/pointers/preview/pointers_01__alpha.doc.pdf>.
What do you think?

In particular, if you find any grave errors, please do not hesitate to
comment. I always make errors. Those I agree are errors will be corrected.
Contents (so far):

1 1 Pointers.
1 1.1 Introduction to the basics.
1 1.1.1 How to obtain a pointer to a given object, and how to use that pointer.
3 1.1.2 The nullpointer value, valid and invalid pointers.
6 1.1.3 How to implement out-arguments by using pointers.
8 1.1.4 How to implement in-arguments by using pointers.
9 1.1.5 How to use C++ style references instead of C style pointers for arguments.
11 1.1.6 How to access main arguments.
12 1.1.7 Const-correctness for pointers (and references).
14 1.2 Run-time polymorphism.
14 1.2.1 Polymorphism.
16 1.2.2 The concept of linked data structures.
17 1.2.3 C-style polymorphism with simulated dynamic types (just one actual type).
19 1.2.4 Basic use of dynamic memory allocation & deallocation.
22 1.2.5 How to use function pointers to simulate dynamic types, C-style.
25 1.2.6 Using real types and inheritance for logical sub-types, mostly C-style.
32 1.2.7 Using vtables, mostly C-style (also a few words about abstract classes, etc.).
38 1.2.8 C++ virtual member functions.
45 1.2.9 C++ destructors and polymorphic delete.
49 1.2.10 Object ownership and the C++ std::auto_ptr.
53 1.2.11 C++ constructors and exception safety for new.
57 1.3 Dynamically allocated objects versus others.
58 1.3.1 Ensure dynamic allocation using C++ access specifiers and copy constructors.
61 – End Of Text –

--
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?
Oct 26 '05
53 4479
Again I ask for comments, corrections, praise, damnations, nits, etc.!

Of the new stuff added since the alpha3 version I think most interesting
is perhaps the section on how to ensure that smart pointers are used.

By discussing that I'm taking a leap, for as far as I know the technique
hasn't been used in production (I've never seen it discussed or used),
so comments about this would especially appreciated. E.g., are there
problems using that with Loki's small object allocator? I don't know,
but I think it appears to be so useful that it deserves discussion, even
if it turns out there are restrictions for very special usage contexts.
PDF document:
<url:
http://home.no.net/dubjai/win32cpptut/special/pointers/preview/pointers_01_beta.doc.pdf>

Examples source code:
<url:
http://home.no.net/dubjai/win32cpptut/special/pointers/preview/examples.zip>

Contents:
Please see the PDF document's table of contents.

--
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?
Nov 22 '05 #51
"Alf P. Steinbach" <al***@start.no> wrote in message
news:43****************@news.individual.net...
Again I ask for comments, corrections, praise, damnations, nits, etc.!

Of the new stuff added since the alpha3 version I think most interesting
is perhaps the section on how to ensure that smart pointers are used.

By discussing that I'm taking a leap, for as far as I know the technique
hasn't been used in production (I've never seen it discussed or used),
so comments about this would especially appreciated. E.g., are there
problems using that with Loki's small object allocator? I don't know,
but I think it appears to be so useful that it deserves discussion, even
if it turns out there are restrictions for very special usage contexts.
PDF document:
<url:
http://home.no.net/dubjai/win32cpptut/special/pointers/preview/pointers_01_beta.doc.pdf>
Examples source code:
<url:
http://home.no.net/dubjai/win32cpptut/special/pointers/preview/examples.zip>
Contents:
Please see the PDF document's table of contents.

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


I think you have done an excellent job from what I have read so far Alf.
I've a way to go to finish chapter one, but I like the style of this very
much.
Not too verbose, but certainly not lacking in substance either.
The © won't do you any good in this case. I'm keeping it!

--
Vince Morgan
Remove UNSPAM
vi****@UNSPAMoptusnet.com.auWhat is the most annoying thing on usenet and in
e-mail?
Nov 28 '05 #52
"Alf P. Steinbach" <al***@start.no> wrote in message
news:43****************@news.individual.net...
Again I ask for comments, corrections, praise, damnations, nits, etc.!

Of the new stuff added since the alpha3 version I think most interesting
is perhaps the section on how to ensure that smart pointers are used.

By discussing that I'm taking a leap, for as far as I know the technique
hasn't been used in production (I've never seen it discussed or used),
so comments about this would especially appreciated. E.g., are there
problems using that with Loki's small object allocator? I don't know,
but I think it appears to be so useful that it deserves discussion, even
if it turns out there are restrictions for very special usage contexts.
PDF document:
<url:
http://home.no.net/dubjai/win32cpptut/special/pointers/preview/pointers_01_beta.doc.pdf> The section: Obtaining a pointer to(also called address of) a given object.
Half way through second paragraph.
<quote>
"However, with the C++98 standard it's not always formally the case that &*p
is

identically the same as writing just p, because the address might not permit
dereferencing. And

when p is a variable, as above, p is an lvalue that can be assigned to,
whereas &*p yields an rvalue."

</quote>

Did you mean *&p as opposed to "&*p"?
Examples source code:
<url:
http://home.no.net/dubjai/win32cpptut/special/pointers/preview/examples.zip>
Contents:
Please see the PDF document's table of contents.

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


Vince Morgan
Remove UNSPAM
vi****@UNSPAMoptusnet.com.au
Nov 28 '05 #53
* Vince Morgan:
PDF document:
<url:
http://home.no.net/dubjai/win32cpptut/special/pointers/preview/pointers_01_beta.doc.pdf>

The section: Obtaining a pointer to(also called address of) a given object.
Half way through second paragraph.
<quote>
"However, with the C++98 standard it's not always formally the case
that &*p is identically the same as writing just p, because the address
might not permit dereferencing. And when p is a variable, as above, p is
an lvalue that can be assigned to, whereas &*p yields an rvalue."
</quote>

Did you mean *&p as opposed to "&*p"?


No.

First case. p is a pointer. If the pointer value permits dereferencing
(e.g., is not a nullpointer), then *p gives you what p points to. &*p
then gives you the address of that object, i.e. the same value as p, but
only if the pointer value permits dereferencing.

Second case. *p is an lvalue, an object that (apart from constness) can
appear as the Left hand side of an assignment. &*p is an rvalue.

Hth.,

- Alf

--
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?
Nov 28 '05 #54

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: chaitu | last post by:
Hi guys, I've written a parallel build program (in Perl) that takes a pre-computed dependency tree of many projects in 2 visual studio .net 2003 solution (.sln) files here at my company, and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
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...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.