Constructor not running

I'm stumped, here's the code that's dying:
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
Town T(350,200,300,200);
class WaterTile
{
    int x,y,sx,sy;
    public:
    WaterTile ()
    {
        sx=150;
        sy=100;
        out<<"Do I even Get here?\n";
        while(1)
        {
        x=rand()%1000;
        y=rand()%600;
        out<<"X="<<x<<" Y="<<y<<endl;
        if (T.in_town(x,y,sx,sy))
        {
            continue;
        }
        if (((sx+x)>1000)||((sy+y)>600))
        {
            continue;
        }
        break;
        }
    }
    bool In_Tile (int xx, int yy, int ssx, int ssy)
    {
        if (checkhit(xx,yy,ssx,ssy,0,x,y,sx,sy,0))
        {
            return true;
        }
        return false;
    }
    void Draw (SDL_Surface* scr)
    {
        images[23]->Draw(scr,x+d_x,y+d_y);
    }
};
WaterTile WT[4];

So, the 'draw' function works great, but the constructor isn't running. Why not? And WT[4] is declared globally, is that the problem?
EDIT: Fixed typo :p
Last edited on
Probably. The order of initialization of global objects is undefined, so for example, if the objects were to be initialized in the order [WT, T, std::coutout], it would not work at all.
Last edited on
It is always safe to use std::cout in a constructor of a static object, but it is designed in such a way to make it possible. What is out, and is it designed in a similar manner?

Using cout instead, your constructor, naturally, runs: http://ideone.com/0yIcH
Topic archived. No new replies allowed.