problem understanding :: operator in bitset class declaration



 DEVELOP > c-Plus-Plus > problem understanding :: operator in bitset class declaration

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 04 Jan 2008 03:14:46 PM
Object: 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
.

User: "Victor Bazarov"

Title: Re: problem understanding :: operator in bitset class declaration 04 Jan 2008 03:21:21 PM
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
.
User: ""

Title: Re: problem understanding :: operator in bitset class declaration 04 Jan 2008 03:30:42 PM
On Jan 4, 4:21 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:

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
.
User: "Victor Bazarov"

Title: Re: problem understanding :: operator in bitset class declaration 04 Jan 2008 03:39:29 PM
wrote:

On Jan 4, 4:21 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:

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
.



User: "James Kanze"

Title: Re: problem understanding :: operator in bitset class declaration 05 Jan 2008 02:51:18 AM
On Jan 4, 10:14 pm,
wrote:

class bitset::reference {
friend class bitset;
reference(); // no public
constructor
public:
~reference();
operator bool () const; // convert to bool
reference& operator=3D ( bool x ); // assign from bool
reference& operator=3D ( 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:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.

User: "Salt_Peter"

Title: Re: problem understanding :: operator in bitset class declaration 05 Jan 2008 03:02:03 AM
On Jan 4, 4:14 pm,
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

.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER