{"id":2029,"date":"2011-02-12T20:20:59","date_gmt":"2011-02-12T11:20:59","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/archives\/2029"},"modified":"2011-02-12T20:21:31","modified_gmt":"2011-02-12T11:21:31","slug":"%e3%83%ab%e3%82%a4%e3%82%b9%e3%81%af%e3%82%a2%e3%83%aa%e3%82%b9%e3%81%ab%e9%9b%bb%e8%a9%b1%e3%81%99%e3%82%8b2","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/2029","title":{"rendered":"\u30eb\u30a4\u30b9\u306f\u30a2\u30ea\u30b9\u306b\u96fb\u8a71\u3059\u308b(2)"},"content":{"rendered":"<p>\n\u524d\u56de\u306f\u3001\u76f4\u63a5\u306e<b>\u7d99\u627f<\/b>\u3092\u4f7f\u3063\u3066 Phone \u306e\u6a5f\u80fd\u3092\u4f7f\u3044\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f<b>\u59d4\u8b72<\/b>\u3092\u4f7f\u3063\u3066\u307e\u3059\u3002<br \/>\n\u82e5\u5e72\u3001\u56de\u308a\u304f\u3069\u304f\u306a\u308b\u5206\u3060\u3051\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u3084\u3084\u3053\u3057\u3044\u306e\u3067\u3059\u304c\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ for \u30eb\u30a4\u30b9\u306f\u30a2\u30ea\u30b9\u306b\u96fb\u8a71\u3059\u308b(2)\n\/\/ Telephone \u30af\u30e9\u30b9\u3092 Person \u3068\u72ec\u7acb\u306b\u6a5f\u80fd\u3055\u305b\u308b\n\n#include &lt;string.h&gt;\n#include &lt;iostream&gt;\nusing namespace std;\n\nclass Person ;\n\nclass Telephone {\nprotected:\n\tTelephone *_telephone;\n\tPerson *_person ;\n\tvoid (Person::*_onPhone)(const void *, int);\n\npublic:\n\t\/\/ \u81ea\u5206\u306e onPhone \u3092\u767b\u9332\n\tvoid setMyPhone(Person *person, void (Person::*onPhone)(const void *, int)) {\n\t\t_person = person ;\n\t\t_onPhone = onPhone;\n\t} \n\t\/\/ \u76f8\u624b\u5148\u3092\u767b\u9332\n\tvoid setPhone( Telephone *telephone ) {\n\t\tthis-&gt;_telephone = telephone ;\n\t}\n\t\/\/ \u30c7\u30fc\u30bf\u3092\u9001\u4fe1\n\tvirtual void sendData( const void *data, int size ) {\n\t\tif ( _telephone != NULL ) {\n\t\t\t_telephone-&gt;onPhone(data,size);\n\t\t}\n\t}\n\t\/\/ \u30c7\u30fc\u30bf\u3092\u53d7\u4fe1\u3059\u308b\u95a2\u6570\n\tvirtual void onPhone( const void *data, int size ) {\n\t\tif ( _onPhone != NULL ) {\n\t\t\t(_person-&gt;*_onPhone)( data, size );\n\t\t}\n\t} \n};\n\nclass Person\n{\npublic:\n\tchar _name&#x5B;30];\n\tTelephone _phone;\npublic:\n\t\/\/ \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\n\tPerson( const char *name ) {\n\t\tstrcpy( _name, name );\n\t\t\/\/ \u81ea\u5206\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u767b\u9332\n\t\t_phone.setMyPhone( this, &amp;Person::onPhone );\n\t}\n\t\/\/ \u76f8\u624b\u306b\u96fb\u8a71\u3092\u639b\u3051\u308b\n\tvoid setPhone( Person *person ) {\n\t\t_phone.setPhone(person-&gt;getPhone());\n\t}\n\t\/\/ \u96fb\u8a71\u3092\u53d7\u3051\u53d6\u308b\u30a2\u30af\u30bb\u30c3\u30b5\n\tTelephone *getPhone() {\n\t\treturn &amp;(this-&gt;_phone);\n\t}\n\t\/\/ \u30c7\u30fc\u30bf\u53d7\u4fe1\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\n\tvirtual void onPhone( const void *data, int size ) {\n\t\tcout &lt;&lt; &amp;quot;to &amp;quot; &lt;&lt; _name &lt;&lt; &amp;quot;: &amp;quot; &lt;&lt; (char*)data &lt;&lt; endl;\n\t}\n\t\/\/ \u30c7\u30fc\u30bf\u9001\u4fe1\u306e\u95a2\u6570\n\tvirtual void sendPhone( const void *data, int size ) {\n\t\tcout &lt;&lt; &amp;quot;from &amp;quot; &lt;&lt; _name &lt;&lt; &amp;quot;: &amp;quot; &lt;&lt; (char*)data &lt;&lt; endl;\n\t\t_phone.sendData( data, size );\n\t}\n};\n\nint main(void)\n{\n\tPerson alice(&amp;quot;alice&amp;quot;);\n\tPerson lewis(&amp;quot;lewis&amp;quot;);\n\n\t\/\/ \u30a2\u30ea\u30b9\u306b\u96fb\u8a71\u3092\u639b\u3051\u308b\u3002\n\tlewis.setPhone( &amp;alice );\n\tlewis.sendPhone( &amp;quot;hello i&#039;m lewis&amp;quot;, 0 );\n\n\treturn 0;\n}\n<\/pre>\n<p>\nTelephone \u3068 Person \u30af\u30e9\u30b9\u306e\u9593\u306b\u306f\u3001\u7d99\u627f\u306e\u95a2\u4fc2\u306f\u3042\u308a\u307e\u305b\u3093\u3002Phone has a Telephone \u3068\u306a\u3063\u3066\u3001has_a \u306e\u95a2\u4fc2\u306b\u306a\u308a\u307e\u3059\u306d\u3002ITelephone \u3092 Person \u30af\u30e9\u30b9\u304c\u7d99\u627f\u3057\u305f\u5834\u5408\u306f is_a \u306e\u95a2\u4fc2\u3067\u3059\u3002\n<\/p>\n<p>\n\u3053\u306e Phone \u6a5f\u80fd\u3092\u4f7f\u3046\u74b0\u5883\u3067\u306f\u3001main \u95a2\u6570\u306e\u547c\u3073\u51fa\u3057\u306f\u5909\u308f\u308a\u307e\u305b\u3093(\u30e1\u30bd\u30c3\u30c9\u540d\u3092\u5909\u3048\u305f\u306e\u3067\u305d\u3053\u3060\u3051\u3067\u3059\uff09\u3002Person \u30af\u30e9\u30b9\u306e\u4e2d\u3067\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u767b\u9332\u3059\u308b Person::setPhone \u30e1\u30bd\u30c3\u30c9\u3067\u306f\u3001\u30e1\u30f3\u30d0\u95a2\u6570\u30dd\u30a4\u30f3\u30bf\u3092\u4f7f\u3044\u307e\u3059\u304c\u3001C# \u306a\u3093\u304b\u3060\u3068\u30c7\u30ea\u30b2\u30fc\u30c8\u3067\u6e08\u307f\u307e\u3059\u3002\u3053\u3053\u306f\u3001C++ \u306a\u306e\u3067\u82e5\u5e72\u3084\u3084\u3053\u3057\u3044\u3053\u3068\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u3068\u3002\u3072\u3068\u3064\u6ce8\u610f\u3057\u305f\u3044\u306e\u304c\u3001\u30ea\u30b9\u30ca\u30fc\u30d1\u30bf\u30fc\u30f3\u3092\u5229\u7528\u3057\u305f\u5834\u5408\u306b\u306f\u3001Person \u30af\u30e9\u30b9\u306f\u306a\u3093\u3089\u304b\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u7d99\u627f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059(Telephone \u30af\u30e9\u30b9\u304b\u3089\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u305f\u3081\uff09\u3002\u3067\u3059\u304c\u3001Person \u30af\u30e9\u30b9\u306e\u7d99\u627f\u5143\u3092\u4f7f\u308f\u305a\u306b\/\u7d99\u627f\u3055\u305b\u305a\u306b\u3001Phone \u306e\u6a5f\u80fd\u304c\u4f7f\u3048\u308b\u3068\u3044\u3046\u70b9\u3067\u3001\u30c7\u30ea\u30b2\u30fc\u30c8\u3084\u95a2\u6570\u30dd\u30a4\u30f3\u30bf\u3092\u4f7f\u3063\u305f\u5834\u5408\u306f\u7570\u306a\u308b\u306e\u3067\u3059\u3002\u3053\u306e\u3042\u305f\u308a\u3001\u5dee\u7570\u304c\u5fae\u5999\u3067\u3059\u304c\u3001<b>\u7d99\u627f\u5143<\/b>\u3068\u3044\u3046\u306e\u304c\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u306d\u3002\n<\/p>\n<p>\n\u3053\u3053\u3067\u3001\u8ee2\u9001\u3059\u308b\u30c7\u30fc\u30bf\u306f\u97f3\u58f0\u3068\u3044\u3046\u3053\u3068\u3067<b>\u6587\u5b57\u5217<\/b>\u3057\u304b\u6271\u3063\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u4efb\u610f\u306e\u30c7\u30fc\u30bf\u3092\u9001\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u5206\u304b\u308a\u307e\u3059\u306d\u3001\n<\/p>\n<p>\n\u30a2\u30ea\u30b9\u306f\u7269\u7406\u8ee2\u9001\u6a5f\u3092\u6301\u3063\u3066\u3044\u308b | Moonmile Solutions Blog<br \/>\n<a href=\"http:\/\/www.moonmile.net\/blog\/archives\/2025\">http:\/\/www.moonmile.net\/blog\/archives\/2025<\/a>\n<\/p>\n<p>\n\u306e\u3068\u3053\u308d\u3067\u8a71\u3057\u305f\u3001\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u306e\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u30d7\u30e9\u30c0\u306e\u30d0\u30c3\u30b0\u3092\u9001\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u3002\n<\/p>\n<p>\n\u3063\u3066\u306a\u8a33\u3067\u3001\u3053\u306e\u8a71\u306f\u6b21\u56de\u306b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306f\u3001\u76f4\u63a5\u306e\u7d99\u627f\u3092\u4f7f\u3063\u3066 Phone \u306e\u6a5f\u80fd\u3092\u4f7f\u3044\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f\u59d4\u8b72\u3092\u4f7f\u3063\u3066\u307e\u3059\u3002 \u82e5\u5e72\u3001\u56de\u308a\u304f\u3069\u304f\u306a\u308b\u5206\u3060\u3051\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u3084\u3084\u3053\u3057\u3044\u306e\u3067\u3059\u304c\u3002 \/\/ for \u30eb\u30a4\u30b9\u306f\u30a2\u30ea\u30b9\u306b\u96fb\u8a71\u3059\u308b(2) \/\/ Telephone &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/2029\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[22],"tags":[],"class_list":["post-2029","post","type-post","status-publish","format-standard","hentry","category-c"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2029","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=2029"}],"version-history":[{"count":1,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2029\/revisions"}],"predecessor-version":[{"id":2030,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2029\/revisions\/2030"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=2029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=2029"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=2029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}