{"id":215390,"date":"2020-11-14T21:02:09","date_gmt":"2020-11-14T13:02:09","guid":{"rendered":"http:\/\/4563.org\/?p=215390"},"modified":"2020-11-14T21:02:09","modified_gmt":"2020-11-14T13:02:09","slug":"c%e7%b1%bb%e7%9a%84%e7%bb%a7%e6%89%bf%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=215390","title":{"rendered":"c++\u7c7b\u7684\u7ee7\u627f\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  c++\u7c7b\u7684\u7ee7\u627f\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : gargar <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>C++\u6e23\u6e23\uff0c\u9047\u5230\u8fd9\u4e2a\u9898\u76ee\uff0c\u8bf7\u95ee <code>Dan(std::function&lt;Niao* ()&gt; createNiao)<\/code> \u662f\u4ec0\u4e48\u7528\u6cd5\uff1f<\/p>\n<p>\u8fd8\u6709\u5e94\u8be5\u600e\u4e48\u6807\u5fd7\uff0c\u624d\u80fd\u77e5\u9053\u4ea7\u751f Egg \u7684\u662f\u54ea\u4e2a\u7c7b\uff08 Niao \u8fd8\u662f Yazi \uff09?<\/p>\n<pre><code>#include &lt;stdexcept&gt; #include &lt;functional&gt;  class Dan;  class Niao { public:     virtual ~Niao() {};     virtual Dan* lay() = 0; };  class Dan { public:     Dan(std::function&lt;Niao* ()&gt; createNiao)     {         throw std::logic_error(\"Waiting to be implemented\");     }      Niao* hatch()     {         throw std::logic_error(\"Waiting to be implemented\");     } };  class Yazi : public Niao { public:     Yazi()     {     }      Dan* lay()     {         throw std::logic_error(\"Waiting to be implemented\");     } };  #ifndef RunTests int main() {     Niao* yazi = new Yazi();      Dan* dan1 = yazi-&gt;lay();     Niao* childYazi1 = dan1-&gt;hatch(); } #endif <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4383062\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : across <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7b80\u5355\u8bf4 std::function \u5c31\u662f\u7c7b\u578b\u5316\u7684 C++\u7248\u672c\u51fd\u6570\u6307\u9488\u3002Niao* () \u662f\u51fd\u6570\u7c7b\u578b\u58f0\u660e\uff0c\u65e0\u5165\u53c2\uff0c\u6709\u8fd4\u56de\u503c\u3002Dan \u7684\u6784\u9020\u51fd\u6570\u5c31\u662f\u8bbe\u5b9a\u4e00\u4e2a\u56de\u8c03\u800c\u5df2\uff0c\u770b\u8fd9\u610f\u601d\u5c31\u662f hatch \u7684\u65f6\u5019\u8c03\u7528\u4e0b createNiao \u5427\u3002<\/p>\n<p>\u770b\u4e86\u534a\u5929\u624d\u53d1\u73b0\u662f\u62fc\u97f3\u00b7\u00b7\u00b7\u00b7                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4383063\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : PepperEgg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u62fc\u97f3\u82f1\u6587\u6df7\u5408\u53d8\u6210\u554a XD                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4383064\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhongrs232 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u4ee3\u7801\u83ab\u540d\u559c\u611f\u54c8\u54c8\u54c8\u54c8                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>c++\u7c7b\u7684\u7ee7\u627f\u95ee\u9898 \u8cc7\u6df1\u5927\u4f6c : &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/215390"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=215390"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/215390\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=215390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=215390"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=215390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}