|
-
September 7th, 2002, 12:04 PM
#1
weired behaviour of std::vector at() function
Hello all,
I am trying to port my code from Win (VC6) to Linux (gcc 2.95).
I am getting a weired compilation error while using the at() function in STL's std::vector.
I want to use at() instead of [] because Mark Allen Weiss in his "Data Structures and Problem .. C++" claims the following::
Range checking can be done by using at; a.at(i) is the same as a[i], except that an error is signalled if i is out-of-bounds.
Code:::
-------
boundsMin.x = my_min(boundsMin.x, vertices.at(ii).x);
boundsMin.y = my_min(boundsMin.y, vertices[ii].y);
boundsMin.z = my_min(boundsMin.z, vertices.at(ii).z);
boundsMin is of type TVec3<double>;
vertices is of type std::vector<TVec3<double>>;
Note that the first and third lines use at(ii). the second line uses [ii];
error:::
--------
Box3D.cpp: In method `Box3D::Box3D(const Vec3DArray &)':
Box3D.cpp:53: no matching function for call to `vector<TVec3<double>,allocator<TVec3<double> > >::at (int &) const'
Box3D.cpp:55: no matching function for call to `vector<TVec3<double>,allocator<TVec3<double> > >::at (int &) const'
I want to clarify the following two points.
1. I don't understand what's wrong with the above code. It runs fine in VC6.
2. I gave only only one argument to at(), but the allocator<TVec3<double>> is automatically added by the compiler. What's going on there ?
Thanks.
Ragu
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|