lizhuo wrote:
hi all:
who can tell me why the function ::f() returns the size of the variable C
not the size of type C?
Cause thats what you asked it to do.
>
// details/inject.cpp
#include <iostream>
int C;
Why not label and initialize the above non-const global appropriately:
int g_n = 0;
Consider sticking it into a namespace.
>
class C {
private:
int i[2];
public:
static int f() {
return sizeof(C);
}
};
int f()
{
return sizeof(C);
}
int main()
{
std::cout << "C::f() = " <<C::f() << ","
<< " ::f() = " <<::f() << std::endl;
}
And since you'll probably then do something like modify the global from
within C::f() and f(), you'll probably write back asking why the
variable does not change as ordained. And the answer to that will be:
inject sequence points in your std::cout statements.