472,779 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1366

"Tony Johansson" <jo*****************@telia.com> wrote in message
news:m5*******************@newsb.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
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...
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...
1
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 ...
3
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...
1
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
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...
8
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...
0
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...
9
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 =...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.