I have a class as follows :
class A
{ //private members here
public:
// other public functions here
template<typename T>
void create(int& no) const // this function creates a static array containing no number of
// elements of type T
{
T vars[no]; // first, int no is a variable, can i create a static array here using a variable?
/* second, I also see that visual studio is telling me "Local variable is not
initialized, does it need to be initialized? i only intend to use it for primitive
types and std::string but say if i needed to use if for a class object does it need
to be initialized? */
}
};
I know that int variables cannot be used to create static arrays like so:
int num=10;
int arr[var]; // error, cannot use a variable to create a static array, it has to be const int
Because the variable has to be const int.
But I've seen code in books where they write code like in create function where they use an int variable to create static arrays of type T. Is this even legal?
Also, why is the visual studio telling me Local variable is not initialized at the declaration of the array?