#include <iostream>
int C;
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;
}
Function
Started by Crane, Dec 04 2006 07:36 AM
3 replies to this topic
#1
Posted 04 December 2006 - 07:36 AM
Why does function ::f() return the size of the variable C not the size of type C?
|
|
|
#2
Posted 04 December 2006 - 09:43 AM
My guess would be that int C is defined before class C, and since sizeof can accept either, it will take the first item defined. C::f(), on the other hand, will go with what it knows best, which is class C.
#3
Posted 04 December 2006 - 04:50 PM
WingedPanther said:
My guess would be that int C is defined before class C, and since sizeof can accept either, it will take the first item defined. C::f(), on the other hand, will go with what it knows best, which is class C.
Agree
#4
Posted 08 December 2006 - 11:12 AM
i also agree


Sign In
Create Account


Back to top









