Re: [ROOT] STL vector::at() function

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sun Mar 30 2003 - 21:00:35 MEST


Hi Paolo,

This is a C++ related question and not a ROOT question.
I recommend you to read documentation about the STL
collection classes. What you do in your example
is illegal use of STL.
You should use the push_back function to enter a value
in your vector or the assignement operator, eg
vettore.reserve(10);
vettore[5] = 55;

Rene Brun

On Sat, 29 Mar 
2003, Paolo ADRAGNA wrote:

> Hello,
> this is not exactly a question related to some ROOT feature, but I am a C++ 
> programmer newby, so I search for answers wherever I can: the RootTalk is a 
> good place I suppose.
> 
> I would like to use the "at" function of <vector> container but during 
> compilation I get the error message
> 
> no matching function for call to `vector<int, allocator<int> >::at (int)'
> 
> I don't think my code is important because right after the error during 
> compilation under ROOT environment I tried a small trial program, pippo.cpp:
> 
> #include <vector>
> #include <iostream>
> 
> void main()
> {
> std::vector<int> vettore;
> vettore.reserve(3);
> vettore.clear();
> vettore.at(5) = 56;
> cout << "Vettore 5 =" << vettore.at(5) << endl;
> }
> 
> Disgracefully I got newly an error message:
> 
> c++ -DHAVE_CONFIG_H -I. -I. -I.. -O2 -O0 -g3 -Wall -fno-exceptions 
> -fno-check-new -c pippo.cpp 
> pippo.cpp: In function `int main ()': 
> pippo.cpp:10: no matching function for call to `vector
> allocator >::at (int)' 
> pippo.cpp:11: no matching function for call to `vector
> allocator >::at (int)' 
> gmake: *** [pippo.o] Error 1 
> *** failed *** 
> 
> I also examined the header file stl_vector.h, but i didn't find any "::at" 
> function. Where is my fault? Can you help me?
> 
> Thank you,
> 
> 				Paolo Adragna
> 
> 
> Paolo Adragna
> INFN Sezione di Pisa
> 



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:10 MET