Storing class in Array

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.

1
2
3
4
int intArray[]; // Array of ints

// ...
int i = intArray[4];  // Gets the fifth element of intArray 

1
2
3
4
5
6
MyClass classArray[]; // Array of MyVlass objects

// ..

MyClass anObj = classArray[2]; // 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.
Topic archived. No new replies allowed.