代码。。Bitwise Copy Semantics
Posted rongminglu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了代码。。Bitwise Copy Semantics相关的知识,希望对你有一定的参考价值。
#include <bits/stdc++.h> using namespace std; struct B { B() { this->chr = 0xcccc; } short chr; }; struct A { B s; int i; }; int main() { int64_t i64 = 0x1234567890abcedfll; A *a = reinterpret_cast<A*>(&i64); cout << hex << a->s.chr << "," << a->i << "," << i64 << endl; int64_t i642 = 0x0; A b(*a); cout << hex << setw(4) << b.s.chr << "," << b.i << "," << *reinterpret_cast<int64_t*>(&b) << endl; return 0; }
输出结果为:
cedf,12345678,1234567890abcedf cedf,12345678,1234567890abcedf
如果修改为:
struct B { B(const B&) { this->chr = 0xcedf; } short chr; };
则结果为:
cedf,12345678,1234567890abcedf cedf,12345678,123456780000cedf
以上是关于代码。。Bitwise Copy Semantics的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces 1004F Sonya and Bitwise OR (线段树)