【发布时间】:2019-03-14 11:19:29
【问题描述】:
我尝试了以下 C++ 代码。但是,printf 和 std::cout 的输出是不同的。为什么?
struct Foo
{
int a;
int b;
int c;
};
int main()
{
printf("%d\n", &Foo::c); // The output is 8
std::cout << &Foo::c << "\n"; // The output is 1
}
【问题讨论】:
-
main.cpp:22:27: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int Foo::*’ [-Wformat=] -
@Angew -- 我正在回复一条现已被删除的评论。它说
Foo::c没有被初始化。
标签: c++