Array in class

Hi, I would appreciate some help with a problem. I want to create a class with a public array in it, but I want the size of the array to be determined by a class parameter. I can't declare it inside the constructor because it will go out of scope... could someone please tell me a way around this? Thanks!
You could use a template class with a template parameter for the size of the internal array, I think.
Use a vector:

1
2
3
4
5
6
7
8
9
10
11
12
#include <vector>

class MyClass
{
private:
  std::vector<int> myArray;

public:
  MyClass(int arraysize)
    : myArray(arraysize)
  { }
};
Thank you!
Topic archived. No new replies allowed.