elements of array have incomplete type

Hi guys,

I am getting the following compile time errors

User\4inarowGUI\main.cpp|18|error: elements of array 'BallTracker tracker [6]' have incomplete type|

C:\Users\User\4inarowGUI\main.cpp|18|error: storage size of 'tracker' isn't known|

I don't understand how the storage size of my class isn't known :/


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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61


#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <vector>

using namespace std;

const int WIDTH = 500;
const int HEIGHT = 500;
bool p1,p2;
SDL_Event event;
SDL_Renderer* renderer;
SDL_Window* window;
class Ball;
class BallTracker;
vector<Ball*> redBall;
vector<Ball*> blueBall;
BallTracker tracker[6];

class BallTracker{

   public:

       int colNumber;
       int amountOfBalls;

       BallTracker(){

           amountOfBalls = 0;

       }
};

class Ball{

   public:
     SDL_Surface* surface;
     SDL_Texture*  texture;
     SDL_Rect destRct;
     int number;
     string color;

     Ball(){

        surface = IMG_Load("red.png");
        texture = SDL_CreateTextureFromSurface(renderer,surface);
        destRct.x = 20;
        destRct.y = 20;
        destRct.h = 80;
        destRct.w = 80;
     }

     ~Ball(){

       SDL_DestroyTexture(texture);

     }
};
I don't understand how the storage size of my class isn't known :/

It is not known at the time you define the tracker array, on line 20.
If you move the definition of tracker below the definition of the BallTracker class it should work fine.
but I declared BallTracker before I declared and defined the array?
I don't understand how the storage size of my class isn't known :/

Looking at your code, and remembering that the compiler reads from the top downwards, where do you think the compiler learns the size of the Balltracker class? Before, or after, you attempt to create an array of six Balltracker objects?


If the compiler only needs to know that something exists, declaring it is enough. For example, a function. Another example; a class that the compiler won't need to know anything else about - only that it exists.

If the compiler needs to know what size something is, declaring it isn't enough; the compiler needs to see the definition.

In this case, the compiler needs to know the size.
good point repeater that makes sense.
Topic archived. No new replies allowed.