problem understanding :: operator in bitset class declaration

S

swcamry

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
 
V

Victor Bazarov

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
 
S

swcamry

To tell the compiler which 'reference' is being defined.


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

V

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
 
V

Victor Bazarov

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
 
J

James Kanze

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.
 
S

Salt_Peter

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top