* problems using vector in gcc3.2
@ 2002-10-13 3:35 david d
2002-10-13 3:55 ` bjorn rohde jensen
2002-10-13 6:18 ` Miguel Ramirez
0 siblings, 2 replies; 3+ messages in thread
From: david d @ 2002-10-13 3:35 UTC (permalink / raw)
To: gcchelp
this peace of code:
#include <iostream>
#include <vector>
using namespace std;
int main(){
std::vector <int> v;
v.push_back(5);
cout<<v[0]<<endl;
const int * beg = v.begin();
return 0;
}
compiles with no warnings or errors in gcc 2.96, but
when I try to compile it with gcc 3.2, I get the
following error message:
[me@my xx]$ gcc -c xx.cpp
xx.cpp: In function `int main()':
xx.cpp:8: cannot convert
`__gnu_cxx::__normal_iterator<int*, std::vector<int,
std::allocator<int> > >' to `const int*' in
initialization
How can one solve this problem (besides compiling the
code with the old compiler)?
thanks in advance
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: problems using vector in gcc3.2
2002-10-13 3:35 problems using vector in gcc3.2 david d
@ 2002-10-13 3:55 ` bjorn rohde jensen
2002-10-13 6:18 ` Miguel Ramirez
1 sibling, 0 replies; 3+ messages in thread
From: bjorn rohde jensen @ 2002-10-13 3:55 UTC (permalink / raw)
To: david d; +Cc: gcchelp
Hi David,
You are supposed to use a std::vector<int>::itterator
and not an int *. It looks like, itterators were implemented
as ordinary pointers in your old compiler, but not in
the new one. The code was accidentally correct with your
old compiler but not portable:)
Yours sincerely,
Bjorn
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: problems using vector in gcc3.2
2002-10-13 3:35 problems using vector in gcc3.2 david d
2002-10-13 3:55 ` bjorn rohde jensen
@ 2002-10-13 6:18 ` Miguel Ramirez
1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ramirez @ 2002-10-13 6:18 UTC (permalink / raw)
To: david d, gcchelp
Hi,
> const int * beg = v.begin();
If you want the pointer you can get it the following way:
const int* beg = &(*(v.begin()));
> xx.cpp: In function `int main()':
> xx.cpp:8: cannot convert
> `__gnu_cxx::__normal_iterator<int*, std::vector<int,
> std::allocator<int> > >' to `const int*' in
> initialization
>
Note that the error message is saying to you:
I cannot convert at compile time from vector<int>::iterator
to const int*.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-10-13 13:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-13 3:35 problems using vector in gcc3.2 david d
2002-10-13 3:55 ` bjorn rohde jensen
2002-10-13 6:18 ` Miguel Ramirez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).