pointers to vectors created outwith classes

I have set up a piece of code where I am declaring a 2 dimensional vector of ints using the following code:
std::vector<std::vector<int> > name

This is created outwith a class. I am trying to create a pointer to this from another file but am having some issues. I am going to use this in order to find out how many elements there are in both the x and y directions.

Does anyone know how to create a pointer to a variable that has been created outwith a class?

Any help with this is greatly appreciated.
Neil
Does anyone know how to create a pointer to a variable that has been created outwith a class?


Without a class? What do you mean?


Passing vectors to a function is done just like anything else.

To pass by reference you'd do it like this:

1
2
3
4
5
6
7
8
9
10
11
12
void somefunction(std::vector< std::vector<int> >& vec2d)
{
  cout << vec2d.size(); // etc
}

int main()
{
  std::vector< std::vector<int> > myvec2d;

  // pass to somefunction
  somefunction(myvec2d);
}
Now that's a word I'd never seen before (outwith). Google says it means outside. Ok.

1
2
3
4
5
6
7
struct Foo {
    std::vector< std::vector<int> >* ptr;
};

std::vector< std::vector<int> > vec;
Foo foo;
foo.ptr = &vec;
Topic archived. No new replies allowed.