小编Ame*_*lie的帖子

为什么C++中可以实例化一个没有实现成员函数的类?

例如:

class B;

class A {
public:
    B f();
};

int main(int, char**) {
    A a; // no exception and error

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

该类A可能是不完整的类型。

为什么A这个例子中可以实例化类呢?

f我知道当代码中调用成员函数时,程序将无法编译。

c++ incomplete-type

27
推荐指数
1
解决办法
2986
查看次数

如何在C中引用main函数之后的静态全局变量

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    // write code here
    printf("%d\n", a);
    
    return EXIT_SUCCESS;
}

static int a = 10;
Run Code Online (Sandbox Code Playgroud)

如何a在注释位置引用静态全局变量?

我知道amain 之前的那个地方不会导致这个问题。我只想知道是否有任何相关的语法可以做到这一点?

c

0
推荐指数
1
解决办法
63
查看次数

标签 统计

c ×1

c++ ×1

incomplete-type ×1