By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,363 Members | 3,622 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,363 IT Pros & Developers. It's quick & easy.

problem understanding :: operator in bitset class declaration

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.