谁能解释为什么以下代码无法编译?至少在g ++ 4.2.4上.
更有趣的是,为什么它会在我将MEMBER转换为int时进行编译?
#include <vector>
class Foo {
public:
static const int MEMBER = 1;
};
int main(){
vector<int> v;
v.push_back( Foo::MEMBER ); // undefined reference to `Foo::MEMBER'
v.push_back( (int) Foo::MEMBER ); // OK
return 0;
}
Run Code Online (Sandbox Code Playgroud) 下面是一个代码部分,无法根据数组是否为静态来检索数组的大小.
struct foo
{
static const char* const a[30];
const char* const b[30];
const int ia = __countOf(a) // compiles
const int ib = __countOf(b) // has compile errors related to initialization
};
Run Code Online (Sandbox Code Playgroud)