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

V

Virchanza

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?
 
M

Marc

Virchanza said:
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.
 
J

Johannes Schaub

Virchanza said:
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 ".".
 
A

Alf P. Steinbach /Usenet

* Johannes Schaub, on 15.05.2011 23:32:
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"
::
 
T

Thomas J. Gritzan

Am 16.05.2011 00:52, schrieb Alf P. Steinbach /Usenet:
* Johannes Schaub, on 15.05.2011 23:32:

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

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

for (int i : vec)
{}
 
M

Marc

Johannes said:
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.
 
N

Noah Roberts

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.
 

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

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top