Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > problem understanding :: operator in bitset class declaration

Reply
Thread Tools

problem understanding :: operator in bitset class declaration

 
 
swcamry@gmail.com
Guest
Posts: n/a
 
      01-04-2008
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
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-04-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
swcamry@gmail.com
Guest
Posts: n/a
 
      01-04-2008
On Jan 4, 4:21 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
> (E-Mail Removed) 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
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      01-04-2008
(E-Mail Removed) wrote:
> On Jan 4, 4:21 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
>> (E-Mail Removed) 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


 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      01-05-2008
On Jan 4, 10:14 pm, (E-Mail Removed) 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:(E-Mail Removed)
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
 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      01-05-2008
On Jan 4, 4:14 pm, (E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bitset<32> and bitset<64> efficiency Ninds C++ 14 12-03-2012 11:02 PM
Understanding an Enum Class Declaration KevinSimonson Java 6 10-02-2010 09:22 PM
operator< for std::bitset Guy.Tristram@gmail.com C++ 2 11-06-2008 02:22 PM
"virtual outside class declaration" and "declaration does not declare anything" kelvSYC C++ 6 05-17-2005 08:58 AM
Function declaration in class declaration Ovidesvideo C++ 4 12-10-2004 06:36 PM



Advertisments