Just Curious....... Why no :: for objects?

Discussion in 'C++' started by Virchanza, May 15, 2011.

  1. Virchanza

    Virchanza Guest

    I'm just curious about why you can't do the following:

    vector<int> vec;

    for ( vec::iterator it = vec.begin(); it != vec.end; ++it )
    {

    }

    Would it not be handy to be able to use :: on objects?
    Virchanza, May 15, 2011
    #1
    1. Advertising

  2. Virchanza

    Marc Guest

    Virchanza wrote:

    >
    > I'm just curious about why you can't do the following:
    >
    > vector<int> vec;
    >
    > for ( vec::iterator it = vec.begin(); it != vec.end; ++it )
    > {
    >
    > }
    >
    > Would it not be handy to be able to use :: on objects?


    I don't think it would have caused too much problem if it had been
    allowed (although that would require way more thinking), but in most
    cases, when you have an element of some type, you also have the given
    type handy (here vector<int>), and in the other cases... well soon
    enough you'll have decltype.
    Marc, May 15, 2011
    #2
    1. Advertising

  3. Virchanza wrote:

    >
    > I'm just curious about why you can't do the following:
    >
    > vector<int> vec;
    >
    > for ( vec::iterator it = vec.begin(); it != vec.end; ++it )
    > {
    >
    > }
    >
    > Would it not be handy to be able to use :: on objects?


    There is one problem: "::" ignores non-{class,enumeration,namespace,type-
    template} names. So if you were to do "vec::begin()" it would ignore your
    local "vec" variable, and look for a vec in a surrounding scope.

    On those grounds, I'm not sure it's possible to allow "::" as a replacement
    for ".".
    Johannes Schaub, May 15, 2011
    #3
  4. * Johannes Schaub, on 15.05.2011 23:32:
    > Virchanza wrote:
    >
    >>
    >> I'm just curious about why you can't do the following:
    >>
    >> vector<int> vec;
    >>
    >> for ( vec::iterator it = vec.begin(); it != vec.end; ++it )
    >> {
    >>
    >> }
    >>
    >> Would it not be handy to be able to use :: on objects?

    >
    > There is one problem: "::" ignores non-{class,enumeration,namespace,type-
    > template} names. So if you were to do "vec::begin()" it would ignore your
    > local "vec" variable, and look for a vec in a surrounding scope.
    >
    > On those grounds, I'm not sure it's possible to allow "::" as a replacement
    > for ".".


    For the above the most handy would IMHO be C++0x "auto".


    Cheers,

    - Alf "o o"
    ::

    --
    blog at <url: http://alfps.wordpress.com>
    Alf P. Steinbach /Usenet, May 15, 2011
    #4
  5. Am 16.05.2011 00:52, schrieb Alf P. Steinbach /Usenet:
    > * Johannes Schaub, on 15.05.2011 23:32:
    >> Virchanza wrote:
    >>
    >>>
    >>> I'm just curious about why you can't do the following:
    >>>
    >>> vector<int> vec;
    >>>
    >>> for ( vec::iterator it = vec.begin(); it != vec.end; ++it )
    >>> {
    >>>
    >>> }
    >>>
    >>> Would it not be handy to be able to use :: on objects?

    >>
    >> There is one problem: "::" ignores non-{class,enumeration,namespace,type-
    >> template} names. So if you were to do "vec::begin()" it would ignore your
    >> local "vec" variable, and look for a vec in a surrounding scope.
    >>
    >> On those grounds, I'm not sure it's possible to allow "::" as a
    >> replacement
    >> for ".".

    >
    > For the above the most handy would IMHO be C++0x "auto".


    Or the new C++0x for loop style:

    for (int i : vec)
    {}

    --
    Thomas
    Thomas J. Gritzan, May 16, 2011
    #5
  6. Virchanza

    Marc Guest

    Johannes Schaub wrote:

    > Virchanza wrote:
    >
    >>
    >> I'm just curious about why you can't do the following:
    >>
    >> vector<int> vec;
    >>
    >> for ( vec::iterator it = vec.begin(); it != vec.end; ++it )
    >> {
    >>
    >> }
    >>
    >> Would it not be handy to be able to use :: on objects?

    >
    > There is one problem: "::" ignores non-{class,enumeration,namespace,type-
    > template} names. So if you were to do "vec::begin()" it would ignore your
    > local "vec" variable, and look for a vec in a surrounding scope.


    He's talking of having different rules, that implies not applying the
    current rules...

    > On those grounds, I'm not sure it's possible to allow "::" as a replacement
    > for ".".


    Er, you seem to have misread the post (or I did). It looks like he
    doesn't want :: to mean . but :: to implicitly apply decltype to its
    left if it is not a type already.
    Marc, May 16, 2011
    #6
  7. Virchanza

    Noah Roberts Guest

    On 5/15/2011 11:47 AM, Virchanza wrote:
    >
    > I'm just curious about why you can't do the following:
    >
    > vector<int> vec;
    >
    > for ( vec::iterator it = vec.begin(); it != vec.end; ++it )
    > {
    >
    > }
    >
    > Would it not be handy to be able to use :: on objects?


    Well, how long have you been a developer?

    Any time you're forced to develop something that deals with some bit of
    information that can mean multiple different things, depending on
    context, you simply make the problem more difficult to solve. Parsers
    would get more complicated, I don't know by how much. So my guess is
    that they didn't do this because it was too much work for too little gain.

    I wish I could do that.

    --
    http://crazycpp.wordpress.com
    Noah Roberts, May 16, 2011
    #7
    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. Replies:
    2
    Views:
    374
    Robert Klemme
    Jan 6, 2006
  2. Elaine Jackson

    just curious

    Elaine Jackson, Sep 6, 2003, in forum: Python
    Replies:
    3
    Views:
    368
    News M Claveau /Hamster-P
    Sep 6, 2003
  3. Ken Parkes

    Just curious

    Ken Parkes, Sep 20, 2004, in forum: Python
    Replies:
    4
    Views:
    324
    Ken Parkes
    Sep 22, 2004
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,840
    Smokey Grindel
    Dec 2, 2006
  5. HoneyMonster
    Replies:
    9
    Views:
    437
    John Roth
    Feb 24, 2012
Loading...

Share This Page