473,898 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a question about understanding some piece of text from a book

Hello!

I'm reading a book about C++ and there is something that I don't understand
so I ask you.
I have marked the section from the book that is of intertest by tagging it
with BOOK START HERE and ending with BOOK ENDING HERE. All that text between
is just a copy from the book.
My question come after the text section.

The book says
BOOK START HERE
"The next example uses the class FileOps which provides three
file-processing functions to find the number of word,characters , and lines
in a file, respectively, using caching. An alternative implementation uses
class attributes that are of reference type instead of mutable members, But
first the Cache must be defined:

struct Cache
{
bool linesCached;
long lines;
bool wordCached;
long words;
bool charsCached;
long chars;

cache();
};

Cache::Cache()
{
linesCached = wordCached = charsCached = false;
lines = words = chars = 0;
}

The structure cache has all its attributes specified as public; this is not
a design flaw because it is hidden from the client.
Now consider the class FileOps, which contains a cache.
class FileOps
{
public:
FileOps(const string, Cache&);
FileOps(const FileOps&);
long lines() const;
long words() const;
long chars() const;
~FileOps();
//should have assignment operator
private:
string filename_;
ifstream fileval_;
Cache& myCache_&;
};

If the variable myCache_ were defined to be of type Cache, then the variable
would represet a nested object, and it would have to be defined as mutable
because its values is modified by constant functions, such as lines().
Reference and pointer attributes have the values referenced by them changed
instead of their own values, and
so they do not have to be specified as mutable."
BOOK ENDING HERE

Now to my question:

Question number 1. Is it possible to use struct as they have done here in
the same way as classes with constructors, destuctors and so on.

Question number 2. How can they say the following "The structure cache has
all its attributes specified as public; this is not a design flaw because it
is hidden from the client". It can't be hidden from the client if its public
or I'm I wrong

Question number 3. What does they mean with this sentence
"Reference and pointer attributes have the values referenced by them changed
instead of their own values, and
so they do not have to be specified as mutable."

//Tony
Jul 23 '05 #1
1 1429

"Tony Johansson" <jo************ *****@telia.com > wrote in message
news:m5******** ***********@new sb.telia.net...
Hello!

I'm reading a book about C++ and there is something that I don't understand so I ask you.
I have marked the section from the book that is of intertest by tagging it
with BOOK START HERE and ending with BOOK ENDING HERE. All that text between is just a copy from the book.
My question come after the text section.

The book says
BOOK START HERE <snip>
BOOK ENDING HERE
Now to my question:

Question number 1. Is it possible to use struct as they have done here in
the same way as classes with constructors, destuctors and so on.
Yes, the only difference between a struct and a class is the default access
specifier. A struct's members are public by default while a class's members
are private by default.

Question number 2. How can they say the following "The structure cache has
all its attributes specified as public; this is not a design flaw because it is hidden from the client". It can't be hidden from the client if its public or I'm I wrong
Class FileOps has a private reference to a Cache. Therefore, Cache's public
members are only accessible from the FileOps class. Hence the client, or
user of the class, can't access Cache's internals, only FileOps can. In
other words, the client must access Cache through FileOps.

Question number 3. What does they mean with this sentence
"Reference and pointer attributes have the values referenced by them changed instead of their own values, and
so they do not have to be specified as mutable."


The content of a reference or pointer is the address of the object it is
pointing to. So these depict a memory location of a given size. If you
modify the referred_to or pointed_to object, you aren't modifying the
reference or pointer.
Jul 23 '05 #2

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

Similar topics

6
1607
by: Doug Mitchell | last post by:
Dear Group, My son who is in grade 7 has *just* started going through the book "Python for the Absolute Beginner" by Michael Dawson. He and I have no programming experience. He is beginning this on an old win 95 computer with Python 2.2 I think. He is getting a bit frustrated with color coding. For example in Chapter 2 page 18 and 19 Mr. Dawson describes a more fancy way of printing "Game Over" on the screen. According to *him*...
5
1818
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:
1
1426
by: Tony Johansson | last post by:
Hello I'm trying to learn XML by reading a book. There is some text in the book that I don't understand so I try to ask you out there. My first question is does this statement mean that the character string from is placed into the attribute with name type <contect type = "from">
3
1351
by: Ron Vecchi | last post by:
I am creating my own MainMenu control similar to VS.Net. (yes I know theirs some out their). I have predominatly been a web developer for about 5 years and am playing with Windows forms. So this should help me learn. My question is about IntPtr. Basically what is it, I know its a pointer but what is a pointer.(of course I know it points to something but how) . In my MenuControl I needed a graphics object in my OnPaint override.
1
1153
by: hema chandran | last post by:
Hello sir I am fresher in DOTNET sir, so plz help me referents book Thank u sir This is my mail i.d hemudotnet@yahoo.com
75
5513
by: Steven T. Hatton | last post by:
No, this is not a troll, and I am not promoting Java, C-flat, D, APL, Bash, Mathematica, SML, or LISP. A college teacher recently posted to this newsgroup regarding her observation that there has been a significant decline in the number of students opting to take courses in C++. I just want to let people know what I believe are the biggest obstacles to C++ language acquisition, and what aspects of the language make it less appealing than...
8
1827
by: boki_pfc | last post by:
Hi Everybody, I am looking for an advice on following: I have that "pleasure" of reading C++ codes that have been written by person(s) that have not attended the same C++ classes that I did or have not read the same C++ books that I have read. This kind of people has written some parts of the code that use notations that I am not familiar with (and that probably also includes also 50 % of other C ++ programmers). While everybody who...
0
1120
by: Jianwei Sun | last post by:
Hello 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.
9
1546
by: lorlarz | last post by:
I still have a question regarding the following code, in a commonly used routine. First, Here's the code in question: Function.prototype.bind = function(){ var fn = this, args = Array.prototype.slice.call(arguments), object = args.shift(); return function(){ return fn.apply(object, args.concat(Array.prototype.slice.call(arguments)));
0
9993
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
10481
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...
0
9658
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...
1
8034
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
7187
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
5877
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...
0
6076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4705
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
3303
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.