Search code examples
c++vectorgdbstdvector

Accessing vector items in GDB


For example, I have such struct in a templated class:

struct Foo{
    int data;
    vector<Foo*> children;
}

And to print out the data value, I can simply do this: (let bar be a pointer to a Foo)

print bar->data

and this works fine. However I would like to also follow children to another Foo. I tried:

print bar->children[0]->data

but it doesn't work. How should I access the items in a vector and use it in print?


Solution

  • With help from this answer, explicitly instantiating the vector fixes the problem.

    For example,

    template class std::vector<double>;