473,803 Members | 4,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Question about this piece of code.

Hello Alf,
* Jianwei Sun:
>Hello An**********@gm ail.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& StackAsLinkedLi st::Pop()
{
if(count==0 )
throw domain_error("s tack is empty");
Object& const result=*list.Fi rst();
list.Extrac t(&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 1117

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

Similar topics

5
1813
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 parts in that spec. Does anyone know who can answer them? Is there maybe an "Annotated CSS 2.1 Spec" ? That is, one with extra explanation added to every complex piece of text. As an example of two of my questions:
17
2140
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 easily decompiled. This would make it very difficult to implement any sort of license restrictions on your app, because anything you write can be easily viewed and cracked. This also removes any privacy for your intellectual property 2. Jim...
7
2492
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 think this is topical, since it's a C question, but please correct me and apologies if I'm wrong). I suppose that it's this way to allow for "generic" pointer modification, but this implies dereferencing the "void **" pointer to get a "void *"...
18
2272
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 herself for this course. so I ask for your point of view. here's the piece of code: Memory management by client!! // Listing 9.4. Memory management by client rather than by server object
21
1800
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 handling requests by proxies? I have Googled my eyes out....and found nothing. (BTW, props to Google for refusing the ridiculous request for their search results.)
2
3646
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 ,int high) { int i =low; int j =high ; int t= a;
1
858
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 Error error handler to determine the stack trace between where the code is executing and where the exception was thrown? Or even just the name of the class and procedure in which the exception was thrown? As far as I can see there's no way to...
68
15720
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; some may find it off-topic or confusing. Disclaimers at end. The code samples are intended to be nearly minimal demonstrations. They are *not* related to any actual application code.
56
3574
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" have invented. It just sounds like so much trivial nitpickery that it's hard to believe it's as common as we've come to believe.
1
1880
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 have a banner indicating that the website being accessed by the user is TEST. This is because, there are some users who have access to both and sometimes they do stuffs in PROD which are meant to be done only in TEST. By displaying somekind of...
0
9564
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7604
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.