Vector's index problem

Dear rooters,
I couldn’t find the solution for my problem on the root talk, so I decided to post a new question.
I have a problem with using a vector or array variable as an index of another vector or array. For example

[code] vector *Type;

vector *KMothNt;

if ((*Type)[ (*KMothNt)[r]]==11)
[/code]
makes an error, but

[code] long mother = (*KMothNt)[r];

if ((*Type)[mother]==11) 

[/code]

works fine.
I’m running root 5.17.05 on Ububntu 7.10, installed from bnl debian distribution without any extra work done on the package. Of course, I can all the time introduce a new variable like in the second example, but it’s not how it’s suppose to be…
I’ll be glad to get any help on how to get around the problem.
Thank you!

#include <vector>
  TYPE& operator[]( size_type index );

I would have thought that size_type was an int, not a long, but those two types are probably the same on many platforms. Anyway…

What does this mean? It doesn’t compile when linking against root libraries? Doesn’t compile inside of root? (.l bla.C+) Doesn’t work with CINT? What’s the error message?

Cheers,
Charles

Hi, Charles,
Thank you for the fast answer.
It crashes when I’m doing

.L file.C CLASS objectname objectname.execute();

where file.C is the source file of the CLASS class.

The error messages are

[quote] *** Break *** segmentation violation
(no debugging symbols found)
Using host libthread_db library “/lib/tls/i686/cmov/libthread_db.so.1”.
Attaching to program: /proc/6888/exe, process 6888
(no debugging symbols found)…done.
(no debugging symbols found)…done.
[Thread debugging using libthread_db enabled]
[New Thread -1225775424 (LWP 6888)]
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
done.
0xffffe410 in __kernel_vsyscall ()
error detected on stdin
The program is running. Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]
Detaching from program: /proc/6888/exe, process 6888
Root > Function execute() busy flag cleared
[/quote]

Cheers,
Renat.

Hi Renat,

I'm not one of the Root guys, but I'll ask what they would ask: Can you try to write a short script that shows the problem (and then attach it)?  Without the code it's not easy to tell what's going on.

Cheers,
   Charles

p.s. Try using .at() instead of []. at() does bound checking.

Thank you, Charles!
After .at() it works.

That actually makes me nervous. If you weren’t reading outside of vector memory bounds, there should be no difference between at() and []. It may mean that you have a problem somewhere else…

Good luck,
Charles

Hi,

please do “.L file.C+” to compile the code. CINT has some problems with operators in certain contexts so it’s safer to ask the compiler.

Cheers, Axel.