class base {
public:
base a;
};
它会导致编译错误.
class base {
public:
static base a;
};
而此代码不会给出编译错误
whereas this code does not give compilation error
因为 static 类成员没有存储在类实例中,这就是 static 可以工作的原因.
Because static class members are not stored in the class instance, that's why a static would work.
将一个对象存储在另一个相同类型的对象中会破坏运行时 - 无限大,对吧?
Storing an object inside another object of the same type would break the runtime - infinite size, right?
sizeof 会返回什么?编译器需要知道对象的大小,但是因为它包含了同类型的对象,所以没有意义.
What would sizeof return? The size of the object needs to be known by the compiler, but since it contains an object of the same type, it doesn't make sense.
这篇关于为什么一个类可以有自己的静态成员,而不是非静态成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
编译器如何处理编译时分支?What do compilers do with compile-time branching?(编译器如何处理编译时分支?)
我可以使用 if (pointer) 而不是 if (pointer != NULL) 吗Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 吗?)
在 C/C++ 中检查空指针Checking for NULL pointer in C/C++(在 C/C++ 中检查空指针)
比较运算符的数学式链接-如“if((5<j<=1))&quMath-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比较运算符的数学式链接-如“if((5<j<=1)))
“if constexpr()"之间的区别与“if()"Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之间的区别与“if())
C++,'if' 表达式中的变量声明C++, variable declaration in #39;if#39; expression(C++,if 表达式中的变量声明)