473,387 Members | 1,579 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,387 software developers and data experts.

Re: Question about this piece of code.

Hello Alf,
* Jianwei Sun:
>Hello An**********@gmail.com,
>>On Aug 10, 11:18 am, Jianwei Sun <jsunnewsgr...@gmail.comwrote:

I am reading a peice of code which is at the following link:
http://www.brpreiss.com/books/opus4/...l#SECTION00712
30 00 000000000000
>
The code is like this:
>
Object& StackAsLinkedList::Pop()
{
if(count==0)
throw domain_error("stack is empty");
Object& const result=*list.First();
list.Extract(&result);
--count;
return result;
}
Does this code return a reference to local variable result? If
this
is
the case, then this code has problem?
Thanks,
J.W.
The list extract function is here:

http://www.brpreiss.com/books/opus4/...SECTION0052100
00 ...- Hide quoted text -

- Show quoted text -

If we ignore that result is a const and the return type is
non-const, it would seem that the returned value (a reference)
refers to an object that has been deleted inside the Extract
function. This, of course, is wrong.
Thank you for verify, I just want to make sure I didn't miss
something
obvious since the author who maintains
this tutorial is a very knowledgeable person and this book is a
5-star
book on amazon.com
Perhaps the author is very knowledgable about data structures and
algorithms, but just doesn't know even the basics about C++ and
programming in general?

For the code isn't even syntactically correct and should not compile,
and the use of a reference here is extremely non-idiomatic and
misleading, but the basic algorith and data structure logic could be
sound: it seems that it could work, if expressed correctly, but that
could be like interpreting as favorably as possible the writings of a
chimpanzee posing as a college professor.

So, I'm pretty sure that if you look up the ACCU C++-oriented review
of that book it will be very far from 5 stars: on the other end of the
scale. ;-)

Cheers, & hth.,

- Alf
Thank you, and I like "that could be like interpreting as favorably as possible
the writings of a
chimpanzee posing as a college professor.".

However, I will still read this book, with more attention to the c++ code.

J.W.
Aug 10 '08 #1
0 1101

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

Similar topics

5
by: Paul | last post by:
I've bought two books on CSS, and found they're no good. Now I'm reading "Cascading Style Sheets, level 2 revision 1 CSS 2.1 Specification" , but it's tough going. I have lots of questions about...
17
by: Rich S. | last post by:
Hello Just like everyone else, I am excited about how easily one can create Windows applications with the .NET platform, but for shareware, I have some serious reservations 1. Your code can be...
7
by: sunglo | last post by:
My doubt comes from trying to understand how thread return values work (I know, it's off topic here), and I'm wondering about the meaning of the "void **" parameter that pthread_join expects (I...
18
by: __PPS__ | last post by:
Hello, I'm a university student and I'm preparing for my final today. I'm reading course notes, I found completely strange piece of code. It makes me laugh, I think the teacher needs to prepare...
21
by: Jim | last post by:
I am trying to write an HTTP/HTTPS proxy server in VB.Net 2005. But, I don't really even know how the internal workings of a proxy should act. Does anyone have anything on the protocols used in...
2
by: pinkfog | last post by:
Hello,all I m just a newbie to c,and now i m learning quick sorting,i dont very undertand this algorrithm,can someone kind to explain it to me? the code: <quote> void quick_sort(int a ,int low...
1
by: Oenone | last post by:
I have a piece of code (which I can't change) that uses On Error for its error handling. It calls into a piece of code in another assembly that Throws an exception. Is there any way in my On...
68
by: James Dow Allen | last post by:
The gcc compiler treats malloc() specially! I have no particular question, but it might be fun to hear from anyone who knows about gcc's special behavior. Some may find this post interesting;...
56
by: infidel | last post by:
Where are they-who-hate-us-for-our-whitespace? Are "they" really that stupid/petty? Are "they" really out there at all? "They" almost sound like a mythical caste of tasteless heathens that "we"...
1
by: rh.krish | last post by:
Hi, I have a unique situation. We have many applications (approx - 20) built on .NET framework 1.1 & 2.0 and hosted in one single IIS website in PROD. We have similar setup in TEST. Now we want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
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
0
BarryA
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...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.