Wierd errors

FIXED, Please go on to next comment
Getting weird errors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <ctime>
#include <cstdlib>

struct enemySpaceShip
{
    int xCoord;
    int yCoord;
    int shipNumber;
};

void displayShips(enemySpaceShip ship[][3])
{
    for (int i = 0; i < 5; i++)
    {
        int j = 0;
        std::cout << "Enemy ship = " << ship[i][j+2];
        std::cout << "X coord = " << ship[i][j];
        std::cout << "Y coord = " << ship[i][j+1];

    }
}

int main()
{
    srand(time(NULL));
    enemySpaceShip ship[5][3];

    for (int i = 0; i < 5; i++)
    {
        int j = 0;
        ship[i][j].xCoord = (rand() % 1024);
        ship[i][j+1].yCoord = (rand() % 768);
        ship[i][j+2].shipNumber = j;
    }


}


Line 17:
no match for 'operator<<' in 'std::operator<< <std::char_traits<char> >((* & std::cout), ((const char*)"Enemy ship = ")) << (*(ship + ((sizetype)(((unsigned int)i) * 36u))))[(j + 2)]'|

I'm new to structures so if the layout of what I want to do is wrong, i would very much appreciate it if you would let me know.
Last edited on
You have an array of 5 arrays of 3 space ships. ship[i][0], ship[i][1] and ship[i][2] are three different space ships. Is that what you want?

If you only want an array of 5 space ships you should create the arrays as
 
enemySpaceShip ship[5];
and get rid of that [j+...] part in the loop.

The error you get is because you are trying to pass a space ship to the << operator. If you want the shipNumber you need to write .shipNumber after the ship like you do in main.
Topic archived. No new replies allowed.