1 2 3 4 5 6
|
public:
string colors;
void printColors (string myColors[], int sizeOfArray)
{
colors = myColors[];
}
|
Here you try to assign value of
array of
strings to a single
string You can assign single element from array of strings to a single string but not a whole array. For example
colors = myColors[2];
On line 36 you are calling
.colors() as if it was a member function but its just data member so no
() are necessary. But that line even if written without
() doesn't do anything anyway.
To display elements in an array you have to work with one element at a time but do that in the loop as you said yourself
1 2 3 4
|
for(int i = 0; i < array_size; ++i)
{
std::cout << array_of_colors[i] << ' ';
}
|
1.
colors on line 38 isn't defined anywhere when you are trying to use it (check out your main function).
2. Even if
myColor1.colors were intended to use instead of
colors you would be subscripting a single
string anyways not an array of strings so you would get only one character out of that string.
For example
std::string str{"Hello!"}; std::cout << str[0] << std::endl;
would give you
3. Even if it was an array and actually defined at a time you use it on line 38 you still cant access all those elements at once and print them out. Use for loop as I showed you