tags:

views:

26

answers:

2

For example, i have a struct and I'm using static function of class to initialize its members. how can i tell the complier that the class exists but it is defined after the structure S?

struct S
{
    S()
    {
        x = C::GetX(); //static functions, GetX() and GetY()
        y = C::GetY();
    }

int x; int y;
};

class C
{
 /.... /
}

Edit: I will also be using struct S in class C

A: 

If you're using member functions of class C in the definition of S, you'll need to declare C before S.

Oli Charlesworth
+2  A: 

Put C first.

Without more context, it's hard to answer in more depth.

struct S;

class C
{
 /.... /
};

struct S
{
    S()
    {
        x = C::GetX(); //static functions, GetX() and GetY()
        y = C::GetY();
    }

int x; int y;
};

Or, you might need to define S::S outside the class S block.

struct S
{
    S();

int x; int y;
};

class C
{
 /.... /
};

S::S()
{
    x = C::GetX(); //static functions, GetX() and GetY()
    y = C::GetY();
}
Potatoswatter