Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 声明一个类/结构_C++ - Fatal编程技术网

C++ 声明一个类/结构

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之前声

例如,我有一个结构,我使用类的静态函数初始化它的成员。如何告诉编译器该类存在,但它是在结构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();
}