C++ 声明一个类/结构
例如,我有一个结构,我使用类的静态函数初始化它的成员。如何告诉编译器该类存在,但它是在结构S之后定义的C++ 声明一个类/结构,c++,C++,例如,我有一个结构,我使用类的静态函数初始化它的成员。如何告诉编译器该类存在,但它是在结构S之后定义的 struct S { S() { x = C::GetX(); //static functions, GetX() and GetY() y = C::GetY(); } int x; int y; }; class C { /.... / } 编辑:我还将在类C中使用结构S。如果在S的定义中使用类C的成员函数,则需要在S之前声
struct S
{
S()
{
x = C::GetX(); //static functions, GetX() and GetY()
y = C::GetY();
}
int x; int y;
};
class C
{
/.... /
}
编辑:我还将在类C中使用结构S。如果在S的定义中使用类C的成员函数,则需要在S之前声明C。将C放在第一位 没有更多的背景,很难更深入地回答
struct S;
class C
{
/.... /
};
struct S
{
S()
{
x = C::GetX(); //static functions, GetX() and GetY()
y = C::GetY();
}
int x; int y;
};
或者,您可能需要在类S块之外定义S::S
struct S
{
S();
int x; int y;
};
class C
{
/.... /
};
S::S()
{
x = C::GetX(); //static functions, GetX() and GetY()
y = C::GetY();
}