How do I go about storing info to an array of class?
I need to do something like this:
info[count] = ReadNameRating(n, r);
Where info is an array of my own class and ReadNameRating reads the name and rating which is two of the variables handled by that class.
You access an element of the array the same way as you would any other array.
int intArray; // Array of ints
int i = intArray; // Gets the fifth element of intArray
MyClass classArray; // Array of MyVlass objects
MyClass anObj = classArray; // Gets the third element of classArray
Edit: But you're much better off learning how to use vectors, instead of arrays.
Last edited on
Either function ReadNameRating() returns a value that has your class as its type, or the return value type can (and will) be converted into your class type. Prefer the first option.