473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

problem understanding :: operator in bitset class declaration

class bitset::reference {
friend class bitset;
reference(); // no public
constructor
public:
~reference();
operator bool () const; // convert to bool
reference& operator= ( bool x ); // assign from bool
reference& operator= ( const reference& x ); // assign from bit
reference& flip(); // flip bit value
bool operator~() const; // return inverse value
}

What is the purpose of resolution operator :: in the above
declaration?
Why did the creator of bitset need to introduce other name
("reference")?


Regards,
Sam
Jan 4 '08 #1
5 2314
sw*****@gmail.com wrote:
class bitset::reference {
friend class bitset;
reference(); // no public
constructor
public:
~reference();
operator bool () const; // convert to bool
reference& operator= ( bool x ); // assign from bool
reference& operator= ( const reference& x ); // assign from bit
reference& flip(); // flip bit value
bool operator~() const; // return inverse value
}
;
What is the purpose of resolution operator :: in the above
declaration?
To tell the compiler which 'reference' is being defined.
Why did the creator of bitset need to introduce other name
("reference")?
Not sure what your question is here, sorry. You need to look
at 'bitset' to see how 'reference' is used to understand.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 4 '08 #2
On Jan 4, 4:21 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
swca...@gmail.com wrote:
class bitset::reference {
friend class bitset;
reference(); // no public
constructor
public:
~reference();
operator bool () const; // convert to bool
reference& operator= ( bool x ); // assign from bool
reference& operator= ( const reference& x ); // assign from bit
reference& flip(); // flip bit value
bool operator~() const; // return inverse value
}

;
What is the purpose of resolution operator :: in the above
declaration?

To tell the compiler which 'reference' is being defined.
Why did the creator of bitset need to introduce other name
("reference")?

Not sure what your question is here, sorry. You need to look
at 'bitset' to see how 'reference' is used to understand.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks V.
Is the 'reference' in the declaration of a bitset class is a C++
keyword or just other name defined in the scope of bitset?
If it's the C++ keyword, what's the use of it?
I am familiar with reference in the following sense, T& tref where
tref is a reference of type T, and never see the use of 'reference' as
a keyword before.
Regards,
Sam
Jan 4 '08 #3
sw*****@gmail.com wrote:
On Jan 4, 4:21 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>swca...@gmail.com wrote:
>>class bitset::reference {
friend class bitset;
reference(); // no public
constructor
public:
~reference();
operator bool () const; // convert to bool
reference& operator= ( bool x ); // assign from bool
reference& operator= ( const reference& x ); // assign from bit
reference& flip(); // flip bit value
bool operator~() const; // return inverse
value }

;
>>What is the purpose of resolution operator :: in the above
declaration?

To tell the compiler which 'reference' is being defined.
>>Why did the creator of bitset need to introduce other name
("reference")?

Not sure what your question is here, sorry. You need to look
at 'bitset' to see how 'reference' is used to understand.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Thanks V.
Is the 'reference' in the declaration of a bitset class is a C++
keyword or just other name defined in the scope of bitset?
It's a name.
If it's the C++ keyword, what's the use of it?
It's not a keyword.
I am familiar with reference in the following sense, T& tref where
tref is a reference of type T, and never see the use of 'reference' as
a keyword before.
It's not a keyword.

Couldn't you just look at the definition of 'bitmap'? Don't you
have a C++ book that contains a list of keywords against which you
could verify 'reference' or any other combination of letters?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 4 '08 #4
On Jan 4, 10:14 pm, swca...@gmail.com wrote:
class bitset::reference {
friend class bitset;
reference(); // no public
constructor
public:
~reference();
operator bool () const; // convert to bool
reference& operator= ( bool x ); // assign from bool
reference& operator= ( const reference& x ); // assign from bit
reference& flip(); // flip bit value
bool operator~() const; // return inverse value

}
What is the purpose of resolution operator :: in the above
declaration? Why did the creator of bitset need to introduce
other name ("reference")?
Because that's what he's definiting. There are two classes
involved here: bitset and bitset::reference. The second is a
nested class---a class that is a member of bitset. It can be
defined in one of two ways:

class bitset
{
class reference { /* definition here */ } ;
} ;

or

class bitset
{
class reference ; // forward declaration
} ;

class bitset::reference { /* definition here */ } ;

Apparently, in the above, the author has chosen the second way.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jan 5 '08 #5
On Jan 4, 4:14 pm, swca...@gmail.com wrote:
class bitset::reference {
friend class bitset;
reference(); // no public
constructor
public:
~reference();
operator bool () const; // convert to bool
reference& operator= ( bool x ); // assign from bool
reference& operator= ( const reference& x ); // assign from bit
reference& flip(); // flip bit value
bool operator~() const; // return inverse value

}

What is the purpose of resolution operator :: in the above
declaration?
Why did the creator of bitset need to introduce other name
("reference")?
Its not another name, its a type. In this case its a proxy class.
The bitset container uses the proxy class as a type definition in its
accessors and operators.
Which in the case of a std::bitset is quite relevant since a bitset<8>
and a bitset<32>, for example, are different types.
>
Regards,
Sam
Jan 5 '08 #6

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

Similar topics

4
by: exits funnel | last post by:
Hello, I have the following code: class A { public: A(int i = 0):asInt(i) { } operator B( ) { return B(asInt); } private:
5
by: James Aguilar | last post by:
Hello, all. I saw this in the provided code of a lab that I have due in a couple of weeks in my algorithms class. It compiled fine in g++ but did not compile with the VC++ compiler. It does...
10
by: Christian Christmann | last post by:
Hi, I added an operator overloader in my template class: graph.h: template <class NODE> class Node {
6
by: ghager | last post by:
Hi all, I must be blind or stupid. Please consider the following code: ---- .... template <class T> class P; template <class T> P<T> operator*(T,const P<T>&); template <class T>
17
by: zirconx | last post by:
I'm trying to understand how the bitwise AND can be used. I've read about what it does but am having trouble applying it practically. I'm working on a system that somebody else wrote and they...
8
by: flamexx7 | last post by:
Can anybody tell me what is wrong with declaration of pointer p ? template<class Tclass Stack { struct Link { T* data; Link* next; Link(T* dat, Link* nxt) : data(dat), next(nxt) {} }* head;...
2
by: syang8 | last post by:
Dear all, I am trying to design classes with stream support. Basically, I want the operator << work for the base class and all the derived classes. If the base class is a template class, and...
2
by: arnuld | last post by:
i am confused on some aspects of bitset class: /* C++ Primer 4/e * chapter 3 * * exercise 3.23 * */ #include <iostream>
3
by: Guy.Tristram | last post by:
Is there any good reason operator< is not defined for std::bitset? It seems to me that: 1 - it would be useful. 2 - it is easy to implement inside the class template. 3 - it is impossible to...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...
0
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,...
0
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...

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.