y‰SŽÒнŒ}zC/C++Ž ..
[
2ch
|
¥Menu
]
¡ƒRƒsƒyƒ‚[ƒh
ƒXƒŒ‚ð’Êí•\ަ
ƒIƒvƒVƒ‡ƒ“ƒ‚[ƒh
‚±‚̽گÄÞ‚ÌURL
¡€–ÚƒeƒLƒXƒg
345:ƒfƒtƒHƒ‹ƒg‚Ì–¼–³‚µ‚³‚ñ 10/04/05 23:05:54 >>343 > ƒƒ“ƒo•Ï”ƒ|ƒCƒ“ƒ^‚ÌŒ^‚Ì‘ã“ü‰‰ŽZŽq‚Ɉˑ¶‚µ‚È‚¢ƒfƒB[ƒvƒRƒs[‚Ì•û–@‚͂Ȃ¢‚Å‚µ‚傤‚©H ‘f’¼‚É•’Ê‚ÉCopy Constructor‚ð‘‚‚Æ‚»‚¤‚È‚ç‚È‚¢H ƒeƒ“ƒvƒŒ[ƒgˆø”‚ðTŒ^‚Æ‚·‚邯A // Copy Constructor MyClass(const MyClass& other) { pointer = new T(*other.pointer); // pointer‚Ͷƒ|ƒCƒ“ƒ^ or ƒXƒ}[ƒgƒ|ƒCƒ“ƒ^Œ^‚Æ‚·‚éB } ‚¶‚áƒ_ƒ‚È‚ñ‚·‚©H 346:345 10/04/05 23:06:50 ‰‰ŽZŽq‚Ì—D懈ʂª•sˆÀ‚ɂȂÁ‚½‚©‚çXC³B // Copy Constructor MyClass(const MyClass& other) { pointer = new T( *( other.pointer ) ); // pointer‚Ͷƒ|ƒCƒ“ƒ^ or ƒXƒ}[ƒgƒ|ƒCƒ“ƒ^Œ^‚Æ‚·‚éB } ‚¶‚áƒ_ƒ‚È‚ñ‚·‚©H 347:ƒfƒtƒHƒ‹ƒg‚Ì–¼–³‚µ‚³‚ñ 10/04/05 23:37:38 ƒƒ“ƒo•Ï”ƒ|ƒCƒ“ƒ^‚Á‚Ä A B::*p; ‚Æ‚©‚Ì‚±‚Æ‚©H ‰˜‚¢‚¯‚Ç‚±‚ê‚łǂ¤‚æB #include <new> class A { public: A() {} }; class B { public: B() : m_a(operator new(sizeof(A))) { } ~B() { operator delete(m_a); } A* GetA() { return reinterpret_cast<A*>(m_a); } const A A1; const A A2; const A A3; void Copy(const A B::*p) { GetA()->~A(); new (GetA()) A(this->*p); } private: void* m_a; }; int main() { B b; b.Copy(&B::A1); b.Copy(&B::A2); b.Copy(&B::A3); }
ŽŸƒy[ƒW
ÅVƒŒƒX•\ަ
ƒXƒŒƒbƒh‚ÌŒŸõ
—ÞŽ—ƒXƒŒˆê——
˜b‘è‚̃jƒ…[ƒX
‚¨‚Ü‚©‚¹ƒŠƒXƒg
¥ƒIƒvƒVƒ‡ƒ“‚ð•\ަ
ƒŒƒXƒWƒƒƒ“ƒv
mixiƒ`ƒFƒbƒNI
Twitter‚É“Še
ƒIƒvƒVƒ‡ƒ“
‚µ‚¨‚è‚ð‹²‚Þ
ƒXƒŒƒbƒh‚É‘ž
ƒXƒŒƒbƒh‚̈ꗗ
‰É‚‚Ԃµ2ch
4062“ú‘O‚ÉXV/255 KB
’S“–:undef