I declared a pointer to an array of objects and it is sending as an argument to constructor of another class. This argument is being sent without mentioning the array size. How can I make a test to know the array size?I cannot send it as argument.
pointer declaration:
Student **ptr=new Student*[5];
declaration of object sending ptr as argument without array size:
If the allocation is succesful, you have to remember the size of the array. It used to be worse because in early versions of C++ you needed to pass the array size to delete. Fortunately, that is no longer the case.
It's safer use is to us an STL collection. It'll take care of admin like that for you.
1 2 3 4
class Student;
std::vector<Student**> ptr(5);
std::clog << "list size is: " << ptr.size() << std::endl;
you should send the size of the array as the second argument.
char arrays end with a 0(zero) character but in case of int arrays its not possible to find the end. so the size is need explicitly.