john.burton.email@gmail.com wrote:[color=blue]
> Victor Bazarov wrote:
>[color=green]
>>john.burton.email@gmail.com wrote:
>>[color=darkred]
>>>I've done some extensive searching and can't seem to find an answer[/color][/color]
>
> to
>[color=green][color=darkred]
>>>this -
>>>
>>>Is it correct to using "using" with templates, for example:
>>>using std::vector;[/color]
>>
>>Yes.
>>
>>[color=darkred]
>>>Or do I need to specify the type too:
>>>using std::vector<int>;[/color]
>>
>>I am not sure this should be OK. This form is reserved for bringing
>>members of that class into the scope, but you specify no members[/color]
>
> there.
>[color=green]
>>Does the declaration have the desired effect? Can you use[/color]
>
> vector<int>
>[color=green]
>>without 'std::' afterwards?
>>
>>Another interesting question, does it instantiate 'std::vector<int>'[/color]
>
> due
>[color=green]
>>to that declaration?
>>
>>[color=darkred]
>>>Both seem to "work" on the compiler I have and I can't find any
>>>documentation saying which is correct, or are both correct?[/color]
>>
>>I always use the first one. Hasn't failed me so far...[/color]
>
>
> Yes I'm sorry I incorrecly said the 2nd form compiled. I made a mistake
> and wasn't compiling the program I thought I was.
>
> A related question though. In the following program -
>
> #include <iostream>
> #include <vector>
>
> using std::vector;
> using std::cout;
>
> int main()
> {
> vector<int> i;
> for(vector<int>::iterator i = i.begin(); i != i.end(); ++i) {[/color]
Naming the iterator 'i' hides the vector. You need to name them
differently to get it to compile.
[color=blue]
> cout << *i << "\n";
> }
> }
>
> (please ignore any stupid errors I'm just typing this into this message
> and it's not possible for me to try it)[/color]
OK.
[color=blue]
> It doesn't compile because it can't find
> vector<int>::iterator
>
> I would have assumed that the "using std::vector" would have brough the
> iterator class into scope too as a member of vector but it doesn't seem
> to have.
> Is this correct? Is there another way to do this? Or is it just a
> deficiency of the compiler? (I can only try this on VC++6 at present)[/color]
VC++ v6 has a bug that prevents it from finding vector<int>::iterator.
It is fixed in VC++ 7.1 (at least that's what I can check with).
Victor