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 1 1398
"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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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 ...
|
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...
|
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
|
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...
|
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...
|
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...
|
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 =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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: 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...
|
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...
| |