Topic: using declaration
Author: Shiva <jshiva@bigfoot.com>
Date: 1999/08/12 Raw View
Hi,
I have some doubts about the using declaration.
The standard is not very clear on a situation like this.
#include <vector>
using std::vector;
How do I now declare a vector iterator
because
vector<int>::iterator vii; // doesn't work on VC++ 6.0
You have to use
std::vector<int>::iterator vii;
Is this a bug in the standard.
--
cheers,
Shiva
http://members.xoom.com/jshiva
clc++ FAQ : http://www.cerfnet.com/~mpcline/c++-faq-lite/
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Shiva <jshiva@bigfoot.com>
Date: 1999/08/13 Raw View
Shiva wrote:
> Hi,
> I have some doubts about the using declaration.
> The standard is not very clear on a situation like this.
> #include <vector>
> using std::vector;
> How do I now declare a vector iterator
> because
> vector<int>::iterator vii; // doesn't work on VC++ 6.0
> You have to use
> std::vector<int>::iterator vii;
> Is this a bug in the standard.
The above line was a typo.
My question actually was
"Is this a bug in the compiler? or is it something which has
been left undefined in the standard ?"
--
cheers,
Shiva
http://members.xoom.com/jshiva
clc++ FAQ : http://www.cerfnet.com/~mpcline/c++-faq-lite/
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Nick Ambrose <nicka@interdyn.com>
Date: 1999/08/13 Raw View
Shiva wrote:
> Hi,
> I have some doubts about the using declaration.
> The standard is not very clear on a situation like this.
>
> #include <vector>
> using std::vector;
>
> How do I now declare a vector iterator
> because
>
> vector<int>::iterator vii; // doesn't work on VC++ 6.0
>
> You have to use
> std::vector<int>::iterator vii;
>
> Is this a bug in the standard.
My suspicion is that it is a bug in the compiler. But I am not familiar
enough with that part of the standard to be sure.
Nick
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: source@netcom.com (David Harmon)
Date: 1999/08/13 Raw View
On 12 Aug 1999 23:24:56 GMT in comp.lang.c++, Shiva <jshiva@bigfoot.com>
wrote:
>#include <vector>
>using std::vector;
>
>
>How do I now declare a vector iterator
>because
>
>vector<int>::iterator vii; // doesn't work on VC++ 6.0
Yet another MSVC bug. The following slips past it:
using std::vector;
typedef vector<int> vec;
vec::iterator vii;
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Janusz Szpilewski <janusz.szpilewski@vz.cit.alcatel.fr>
Date: 1999/08/13 Raw View
Shiva wrote:
>
>
> > vector<int>::iterator vii; // doesn't work on VC++ 6.0
> > You have to use
> > std::vector<int>::iterator vii;
> > Is this a bug in the standard.
> "Is this a bug in the compiler? or is it something which has
> been left undefined in the standard ?"
I have not been working with VC++ for a while but I recall that there is
really a bug concerning namespaces in VC++6. I believe it was discussed
on VC++ related NGs.
I am not sure of the standard but according to Stroustrup, the "using"
directive makes all names from a given namespace visible in your current
translation unit.
So if
vector<int>::iterator vii
is visible in the std namespace it should be also visible in your
current one without the scope override operation.
Greetings,
JS
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Salters <msalters@lucent.com>
Date: 1999/06/25 Raw View
gbush@my-deja.com wrote:
> In article <7kbp56$bh7$1@engnews1.eng.sun.com>,
> clamage@eng.sun.com (Steve Clamage) wrote:
> > You don't have exactly that problem in C or C++:
> > int* q = &p->foo->bar[i].q->rec[j];
> > q->a = 2;
> > q->b = 3;
> > q->c = 4;
> > This approach has exactly the semantics of the Pascal "with",
> > by the way, with the advantage of making the stability of q
> > explicit.
> Yes, you can do that. Is it better than "with"? I trow not. Somebody
> may even try to delete that pointer or misuse it in any other way, that
> won't happen with "with."
Right. That's why in C++ a reference can be used:
int &q=p->foo->bar[i]->rec[j];
q.a=2;
q.b=3;
q.c=4;
That definitely is better than "with"
Of course, anybody who writes delete &q should be fired.
Michiel Salters
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: gbush@my-deja.com
Date: 1999/06/23 Raw View
In article <7kbp56$bh7$1@engnews1.eng.sun.com>,
clamage@eng.sun.com (Steve Clamage) wrote:
> You don't have exactly that problem in C or C++:
> int* q = &p->foo->bar[i].q->rec[j];
> q->a = 2;
> q->b = 3;
> q->c = 4;
> This approach has exactly the semantics of the Pascal "with",
> by the way, with the advantage of making the stability of q
> explicit.
Yes, you can do that. Is it better than "with"? I trow not. Somebody
may even try to delete that pointer or misuse it in any other way, that
won't happen with "with."
All the other criticism is equally applicable to using-directives and
using-member-declarations, but they, nevetherless, are in the standard
and nobody questions their presence there.
Gene.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: sbnaran@localhost.localdomain (Siemel Naran)
Date: 1999/06/18 Raw View
On 17 Jun 99 16:52:07 GMT, gbush@my-deja.com <gbush@my-deja.com> wrote:
>void foo()
>{
> A a;
> using a::i;
> i=0; // ok
> j=0; // error
> using a;
> j=0; // ok
>}
To me, the statement
i=0;
says "assign to the local variable 'i' the value '0'". But more careful
analysis shows that 'i' is an alias for a.i, so that the statement really
means something else. In conclusion, I think that the using-declarations
may make program comprehension and maintainance more difficult.
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: clamage@eng.sun.com (Steve Clamage)
Date: 1999/06/18 Raw View
gbush@my-deja.com writes:
>Standard contains a convenient specifications for using-declaration as
>a member-declaration (7.3.3). The question is, why the standard went
>only that far and no farther. It would be convenient to allow using
>using-declaration for an instance of any class, struct, union, enum.
>Pascal, for example, has "with" construct that saves a lot of typing
>and makes code more readable.
The "with" statement in Pascal does save typing, but in my
experience made code more readable only in the context of
initializing the members of a record:
with p^ do begin
i := a;
j := b;
k := i + 2;
m := j + c;
end;
Everywhere else, it added to the problem of deep scope nesting --
when looking at code you were never sure which scope an identifier
came from. The subtle semantics of the "with" statement also caused
some confusion. (The argument of the "with" was evaluated just
once, at the start. Inside the block above, plain 'k' and 'p^k'
would refer to different objects if the value of p was changed.)
The "with" was also helpful in Pascal when you had a complicated
path:
with p^.foo^.bar[i].q^.rec[j] do ...
Since Pascal didn't let you create arbitrary pointers, you
really would have a mess if instead you had to write
p^.foo^.bar[i].q^.rec[j].a := 2;
p^.foo^.bar[i].q^.rec[j].b := 3;
p^.foo^.bar[i].q^.rec[j].c := 4;
You don't have exactly that problem in C or C++:
int* q = &p->foo->bar[i].q->rec[j];
q->a = 2;
q->b = 3;
q->c = 4;
This approach has exactly the semantics of the Pascal "with",
by the way, with the advantage of making the stability of q
explicit.
In C++, you feel less of a need for a "with", since class members
will ordinarily be initialized in a constructor, or dealt with
individually in member functions. In a member function, you have
a built-in "with" for the class type:
T::T() : a(2), b(3), c(4) { }
T::f() { a = 2; b = 3; c = 4; }
I believe the topic was discussed informally early in the C++
standardization process, with no support for adding "with"
to C++. I don't remember seeing a formal proposal.
--
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: gbush@my-deja.com
Date: 1999/06/17 Raw View
Standard contains a convenient specifications for using-declaration as
a member-declaration (7.3.3). The question is, why the standard went
only that far and no farther. It would be convenient to allow using
using-declaration for an instance of any class, struct, union, enum.
Pascal, for example, has "with" construct that saves a lot of typing
and makes code more readable. Why not to allow the same functionality
using using-declaration:
struct A { int i; int j};
void foo()
{
A a;
using a::i;
i=0; // ok
j=0; // error
using a;
j=0; // ok
}
Gene.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]