473,806 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stroustrup: chapter 4

i have 2 problems:

1.) in section 4.2 he uses:

bool is_open(File*)

i want to know why he uses the pointer, instead of these 2:

bool is_open(File) or bool is_open(File&)
2.) section 4.9, Stroustrup says:

double sqrt(double);
enum Beer { Carlsberg, Tuborg, Thor };
namespace NS { int a; }
these are declarations only, as per my point of view but Stroustrup
says these are definitions. how ?

thanks

Mar 4 '07 #1
14 2330
arnuld wrote:
i have 2 problems:

1.) in section 4.2 he uses:

bool is_open(File*)

i want to know why he uses the pointer, instead of these 2:

bool is_open(File) or bool is_open(File&)
The point is you can use a bool to indicate logical result. Whether the
parameter should be passed by value, reference or pointer is the
author's freedom.
>

2.) section 4.9, Stroustrup says:

double sqrt(double);
enum Beer { Carlsberg, Tuborg, Thor };
namespace NS { int a; }
these are declarations only, as per my point of view but Stroustrup
says these are definitions. how ?
The exact text is quoted below:

Of the declarations above, only

double sqrt(double);
extern int error_number;
struct User;

are not also definitions;...
So clearly the author does NOT regard them as definitions. What makes
you think the author says otherwise?

>
thanks
Welcome

Ben
Mar 4 '07 #2
On Mar 4, 10:17 am, benben <benhonghatgmai ldotcom@nospamw rote:
arnuld wrote:
bool is_open(File) or bool is_open(File&)

The point is you can use a bool to indicate logical result. Whether the
parameter should be passed by value, reference or pointer is the
author's freedom.
ok, fine. BTW, as a newbie to C++, i feel, Stroustrup always
complicates things.

double sqrt(double);
enum Beer { Carlsberg, Tuborg, Thor };
namespace NS { int a; }
these are declarations only, as per my point of view but Stroustrup
says these are definitions. how ?

The exact text is quoted below:

Of the declarations above, only

double sqrt(double);
extern int error_number;
struct User;

are not also definitions;...
the last 3 you wrote, are the *only* ones that are "declaratio ns
without definitions". Stroustrup says the three declarations *i*
posted are "declaratio ns with definitions" and to me they look like
"declaratio ns without definitions".

i want to know WHY the 3 declarations i posted are "declaratio ns with
defintions"?
So clearly the author does NOT regard them as definitions. What makes
you think the author says otherwise?
that's about your 3 declaration . what about my 3.

Mar 4 '07 #3
On Mar 4, 11:40 am, "arnuld" <geek.arn...@gm ail.comwrote:
i have 2 problems:

1.) in section 4.2 he uses:

bool is_open(File*)

i want to know why he uses the pointer, instead of these 2:

bool is_open(File) or bool is_open(File&)
A file would normally be considered to have object semantics rather
than value semantics so you have to use either a pointer or a
reference. Copying the File object would then give two references to
the file to be manipulated separately. Not what you want.

It's probable that most people now would prefer the reference rather
than the pointer as the argument isn't in any sense optional, but this
also depends on how the File object is created - I don't have a copy
of the book handy to see the context.
>
2.) section 4.9, Stroustrup says:

double sqrt(double);
enum Beer { Carlsberg, Tuborg, Thor };
namespace NS { int a; }

these are declarations only, as per my point of view but Stroustrup
says these are definitions. how ?

thanks
I think the standard terminology these days would be to say that the
first (being a function prototype) is a declaration. The second is a
definition because it defines the members of the enum.

For the last I think you might say that the namespace is defined
(notwithstandin g that it can be opened again later) and that the
integer a is declared. I suspect that some people would use different
terminology for these last two.
K

Mar 4 '07 #4
On Mar 4, 10:59 am, "Kirit Sælensminde" <kirit.saelensm i...@gmail.comw rote:
bool is_open(File) or bool is_open(File&)

A file would normally be considered to have object semantics rather
than value semantics so you have to use either a pointer or a
reference. Copying the File object would then give two references to
the file to be manipulated separately. Not what you want.
ok
It's probable that most people now would prefer the reference rather
than the pointer as the argument isn't in any sense optional, but this
also depends on how the File object is created - I don't have a copy
of the book handy to see the context.
a File, is simply a File on my hard disk.

2.) section 4.9, Stroustrup says:
double sqrt(double);
enum Beer { Carlsberg, Tuborg, Thor };
namespace NS { int a; }
these are declarations only, as per my point of view but Stroustrup
says these are definitions. how ?
thanks

I think the standard terminology these days would be to say that the
first (being a function prototype) is a declaration. The second is a
definition because it defines the members of the enum.

For the last I think you might say that the namespace is defined
(notwithstandin g that it can be opened again later) and that the
integer a is declared. I suspect that some people would use different
terminology for these last two.

K
quite confusing IMVHO

Mar 4 '07 #5
ok, fine. BTW, as a newbie to C++, i feel, Stroustrup always
complicates things.
It's a good book in many ways, but not one to learn C++ from.
Mar 4 '07 #6
On Mar 4, 2:27 pm, John Harrison <john_androni.. .@hotmail.comwr ote:
ok, fine. BTW, as a newbie to C++, i feel, Stroustrup always
complicates things.

It's a good book in many ways, but not one to learn C++ from.
i know very well.
the only one/other good book available in my country is "Thinking in C+
+" where Eckel makes heavy-use of C. i do not know C. i think i have
discussed it enough here.

Mar 4 '07 #7
arnuld wrote:
>On Mar 4, 10:59 am, "Kirit Sælensminde"
<kirit.saelens mi...@gmail.com wrote:
>>bool is_open(File) or bool is_open(File&)

A file would normally be considered to have object semantics rather
than value semantics so you have to use either a pointer or a
reference. Copying the File object would then give two references to
the file to be manipulated separately. Not what you want.

ok
>It's probable that most people now would prefer the reference rather
than the pointer as the argument isn't in any sense optional, but
this
also depends on how the File object is created - I don't have a copy
of the book handy to see the context.

a File, is simply a File on my hard disk.

>>2.) section 4.9, Stroustrup says:
>>double sqrt(double);
enum Beer { Carlsberg, Tuborg, Thor };
namespace NS { int a; }
>>these are declarations only, as per my point of view but Stroustrup
says these are definitions. how ?
>>thanks

I think the standard terminology these days would be to say that the
first (being a function prototype) is a declaration. The second is a
definition because it defines the members of the enum.

For the last I think you might say that the namespace is defined
(notwithstandi ng that it can be opened again later) and that the
integer a is declared. I suspect that some people would use different
terminology for these last two.

K

quite confusing IMVHO
It is. :-)

Sometimes we need very precise wordning for a technical discussion. The
difference between a declaration and a definition is at that level.

Basically, a declaration introduces a name without spelling out much detail
about it. For example:

class x;

declares that x is the name of a class. We don't know what kind of class.
On the other hand

class x
{
// functions and member variables goes here
};

is a definition of the class x. It not only tells us that x is a class, it
also spells out the details.
(And adding to the confusion, a definition without a preceding declaration,
serves as BOTH a declaration and a definition, as it introduces the name AND
gives all the details. Don't bother with this until later).

Bo Persson
Mar 4 '07 #8
arnuld wrote:
>On Mar 4, 10:17 am, benben <benhonghatgmai ldotcom@nospamw rote:
arnuld wrote:
>>bool is_open(File) or bool is_open(File&)

The point is you can use a bool to indicate logical result. Whether
the parameter should be passed by value, reference or pointer is the
author's freedom.

ok, fine. BTW, as a newbie to C++, i feel, Stroustrup always
complicates things.
I believe that the THINGS just are complicated, and that Stroustrup tries
hard to explain all the finer points. The book is not a gentle introduction,
but a complete explanation of how the language works.

Leaving out the details just wouldn't work here.
Bo Persson
Mar 4 '07 #9
arnuld wrote:
>On Mar 4, 10:17 am, benben <benhonghatgmai ldotcom@nospamw rote:
arnuld wrote:
>>bool is_open(File) or bool is_open(File&)
The point is you can use a bool to indicate logical result. Whether the
parameter should be passed by value, reference or pointer is the
author's freedom.

ok, fine. BTW, as a newbie to C++, i feel, Stroustrup always
complicates things.
I would not want to comment on the way I consider how the person in
question manages things. But if I were to, the example you have given
would not be my evidence either.
>
>>double sqrt(double);
enum Beer { Carlsberg, Tuborg, Thor };
namespace NS { int a; }
these are declarations only, as per my point of view but Stroustrup
says these are definitions. how ?
[snip]
>
i want to know WHY the 3 declarations i posted are "declaratio ns with
defintions"?
Okay. Here we go.

1)
double sqrt(double);

This is a declaration since it introduces the name 'sqrt'; it is not a
definition since it doesn't tell you how it works. This is on the
declaration-but-not-definition list. Read carefully.

2)
enum Beer{Carlsberg, Tuborg, Thor};

This is a declaration since it introduces the name 'Beer'; in addition,
it is also a definition as it gives every detail of what Beer is.

3)
namespace NS{int a;}

This is a declaration since it introduces the name NS; it is also a
definition since it tells you what to expect in NS. Also, it declares
and defines NS::a.
>
>So clearly the author does NOT regard them as definitions. What makes
you think the author says otherwise?

that's about your 3 declaration . what about my 3.
See above.

Ben
Mar 5 '07 #10

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

Similar topics

26
3161
by: Oplec | last post by:
Hi, I am learning standard C++ as a hobby. The C++ Programming Language : Special Edition has been the principal source for my information. I read the entirety of the book and concluded that I had done myself a disservice by having not attempted and completed the exercises. I intend to rectify that. My current routine is to read a chapter and then attempt every exercise problem, and I find that this process is leading to a greater...
11
5700
by: Steven T. Hatton | last post by:
In TC++PL(SE) Stroustrup asserts there is a companion reference called _The Annotated C++ Language Standard_ by Koenig & Stroustrup. It doesn't show up on a google. What gives here? I know there is mention of a problem here: http://www.research.att.com/~bs/bs_faq.html#ARM I guess this is the same work? This seems to mean there is a complete reference manual written by the two most qualified authors laying fallow. I find that disturbing....
1
1958
by: Mike | last post by:
Hi, I'm auctioning the book "The C++ Programming Language" 3rd Ed. by Bjarne Stroustrup on ebay, details as follows or see eBay item number 250030480853. Softback. Condition : Good. Pub. Addison Wesley 1997. 3rd Edition. 910 pages. "The C++ Programming Language" by Bjarne Stroustrup is the classic C++
11
2139
by: arnuld | last post by:
this is the code which runs without any trouble: ----------------------------------------------------- #include <iostream> #include <string> #include <vector> struct Entry { std::string name; int e_num;
14
4971
by: arnuld | last post by:
Stroustrup starts chapter 6 with a programme for desk-calculator: here is a grammer for the langugae accepted by the calcualtor: program: END // END is end-of-input expr_list END expr_list: expression PRINT // PRINT is semicolon expression PRINT expr_list
0
1755
by: arnuld | last post by:
Stroustrup has a table in section 4.9 of declarations and definitions. he asks to write a similar table but in opposite sense: char ch; // declaration with definition he asks to do the opposite as an exercise which is writing it as a "declaration without definition". please check whether i am right or wrong:
0
1760
by: arnuld | last post by:
this programme runs without any trouble. it took 45 minutes of typing. i posted it here so that people can save their precious time: // Stroustrup special edition // chapter 4 exercise 2 // printing the sizes of different types
14
2483
by: arnuld | last post by:
there is no "compile-time error". after i enter input and hit ENTER i get a run-time error. here is the code: ---------- PROGRAMME -------------- /* Stroustrup, 5.9, exercise 11 STATEMENT: Read a sequence of words from the input. use "quit" as the word
1
3535
by: blangela | last post by:
Bjarne Stroustrup has a new text coming out called "Programming: Principles and Practice Using C++" (ISBN: 0321543726), due to be published in December of this year. Some of the features of this new text include: *Its history: The text was developed in the author's introductory programming course at Texas A&M and has been used successfully by hundreds of students.
0
9719
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
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
10366
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...
1
10371
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9187
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6877
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
5546
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
4329
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
2
3850
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.