I want to create an array to store actual objects and not pointers to objects in C++?
Can somebody explain how do I do that? is it better to use vectors or just directly like:
Student s [10];
OR
Student s [10][];
Using:
Student s [10];
Creates an array of 10 Student instances.
I think that Student s [10][]; is invalid.
But with C++ I'd not use C type arrays, it's better to use classes like std::vector or C++0x std::array which may not be available with not up-to date standard libraries/compilers.
Example for the above with a std::vector
#include <vector>
...
std::vector<Student> students(10);
And with an std::array:
#include <array>
...
std::array<Student, 10> students;
std::vector has no fixed size, you can .push_back() elements into it (and remove them). You can retrieve the current size with .size().std::vector<Student> students(10);) it has this as its initial size. If you don't remove elements from or insert elements into the std::vector the size does not change and you can use your fixed size. But unfortunately you cannot fix the size of the vector to a certain amount, but this should not worry you.Don't use arrays. Arrays are C not c++. Use std::vector instead, which is the C++ way to handle this.
[]is valid syntax.