相关疑难解决方法(0)

什么是C++中的"翻译单元"

我正在阅读Meyers编写的"Effective C++",并且遇到了"翻译单元"一词.

有人可以给我一个解释:

1)究竟是什么

2)在使用C++编程时,我应该何时考虑使用它

3)如果它只与C++有关,或者它可以与其他编程语言一起使用

我可能已经在不知道术语的情况下使用它了....

c++

221
推荐指数
6
解决办法
6万
查看次数

为什么我不能在类中初始化非const静态成员或静态数组?

为什么我不能在类中初始化非const static成员或static数组?

class A
{
    static const int a = 3;
    static int b = 3;
    static const int c[2] = { 1, 2 };
    static int d[2] = { 1, 2 };
};

int main()
{
    A a;

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

编译器发出以下错误:

g++ main.cpp
main.cpp:4:17: error: ISO C++ forbids in-class initialization of non-const static member ‘b’
main.cpp:5:26: error: a brace-enclosed initializer is not allowed here before ‘{’ token
main.cpp:5:33: error: invalid in-class initialization of static data …
Run Code Online (Sandbox Code Playgroud)

c++ static const

93
推荐指数
3
解决办法
9万
查看次数

标签 统计

c++ ×2

const ×1

static ×1