Usually when you "pass X to Y" it means you are passing a parameter X to a function Y.
A class is not a function: it is a collection of data and functions.
That said, you can do what is called "operator overloading" for a class.
Then instead of a function you'll use an operator (which is basically a function in disguise).
int my_int_array[10];
// the traditional way (C and C++)
void func1(int *arr, int size)
{
}
// passing by reference (C++ only)
void func2(int (&arr)[10])
{
}
int main()
{
func1(my_int_array, 10);
func2(my_int_array);
}
Well, for example, the user inputs a series of numbers and then it gets maniuplated in the class. How would I pass someArray[] to the class?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class myArray
{
//Add the elements of the array, for example
//Then how would I pass the array back to the main function??
};
int main()
{
cout << "Enter and array";
int someArray[3];
for (int i = 0; i < 3; i++)
cin >> someArray[i]
//How would I pass someArray[] to the class to maipulate it?
}
In your example, someArray is data.
Maybe you want this data to be a part of the class myArray.
1 2 3 4 5 6
class myArray
{
private:
int someArray[3];
};
Now, since myArray contains the data, it would make sense for it to also contain functions for reading it.
Basically we move the reading of someArray into the myArray class.
That answers my question! Appreciate it! And yes I will read those. I hear vectors are much easier, not quite there yet though, still making my way through the tutorials. Thanks!