dynamic array

I have a quick question.
I have a class in which i want to create an array, the size of which is only known at run time. Can i create this array in the class constructor and still be able to access it from the class functions? Or do i need to use a vector declared in the .h file and populate it in the constructor once the size is known?

You could give both a try :)
I tried creating the array in my class constructor, its not declared in the h file, but i cannot then access it from the class methods, I'd rather work with an array.
1
2
3
4
5
6
7
8
9
class MyClass
{
    std::vector<int> my_array;
public:
    MyClass(std::size_t sizeofarray)
    : my_array(sizeofarray)
    {
    }
};
Last edited on
Cheers mate,
Topic archived. No new replies allowed.