problem understanding :: operator in bitset class declaration

Discussion in 'C++' started by swcamry@gmail.com, Jan 4, 2008.

  1. Guest

    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, 2008
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Jan 4, 2008
    #2
    1. Advertising

  3. Guest

    On Jan 4, 4:21 pm, "Victor Bazarov" <> wrote:
    > 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, 2008
    #3
  4. wrote:
    > On Jan 4, 4:21 pm, "Victor Bazarov" <> wrote:
    >> 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
     
    Victor Bazarov, Jan 4, 2008
    #4
  5. James Kanze Guest

    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= ( 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:
    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
     
    James Kanze, Jan 5, 2008
    #5
  6. Salt_Peter Guest

    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
     
    Salt_Peter, Jan 5, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ovidesvideo
    Replies:
    4
    Views:
    550
    Andrey Tarasevich
    Dec 10, 2004
  2. kelvSYC
    Replies:
    6
    Views:
    7,365
    Richard Herring
    May 17, 2005
  3. Replies:
    2
    Views:
    359
    Kai-Uwe Bux
    Nov 6, 2008
  4. KevinSimonson

    Understanding an Enum Class Declaration

    KevinSimonson, Oct 1, 2010, in forum: Java
    Replies:
    6
    Views:
    598
    Roedy Green
    Oct 2, 2010
  5. Ninds
    Replies:
    14
    Views:
    860
    W Karas
    Dec 3, 2012
Loading...

Share This Page