{"id":94233,"date":"2020-04-28T15:34:19","date_gmt":"2020-04-28T07:34:19","guid":{"rendered":"http:\/\/4563.org\/?p=94233"},"modified":"2020-04-28T15:34:19","modified_gmt":"2020-04-28T07:34:19","slug":"%e6%83%b3%e8%af%b7%e6%95%99%e4%b8%80%e4%b8%aa-c-%e5%85%b3%e4%ba%8e%e5%88%9d%e5%a7%8b%e5%8c%96%e7%b1%bb%e6%97%b6%e5%ae%9a%e4%b9%89%e5%92%8c%e5%a3%b0%e6%98%8e%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=94233","title":{"rendered":"\u60f3\u8bf7\u6559\u4e00\u4e2a C++ \u5173\u4e8e\u521d\u59cb\u5316\u7c7b\u65f6\u5b9a\u4e49\u548c\u58f0\u660e\u7684\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u60f3\u8bf7\u6559\u4e00\u4e2a C++ \u5173\u4e8e\u521d\u59cb\u5316\u7c7b\u65f6\u5b9a\u4e49\u548c\u58f0\u660e\u7684\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Waihinchan <\/span>  <span><i><\/i> 18<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6211\u6700\u8fd1\u5728 openframework \u505a\u4f5c\u54c1\u7684\u65f6\u5019\u9047\u5230\u4e86\u4e00\u4e2a\u56f0\u96be\uff0c\u5728\u5b9e\u4f8b\u5316\u4e00\u4e2a\u7c7b\u7684\u65f6\u5019\u6211\u53d1\u73b0\u5982\u679c\u7c7b\u672c\u8eab\u5b9a\u4e49\u4e86\u6784\u9020\u5668\uff0c\u90a3\u6211\u5728\u5b9e\u4f8b\u5316\u7684\u65f6\u5019\u5c31\u5fc5\u987b\u5e26\u6784\u9020\u5668\u3002\u6709\u6ca1\u6709\u529e\u6cd5\u6211\u5148\u58f0\u660e\uff0c\u7136\u540e\u6211\u518d\u5728\u522b\u7684\u51fd\u6570\u91cc\u9762\u6784\u9020\u5462\uff1f<\/p>\n<p>\u6bd4\u5982\u8bf4\u6709\u8fd9\u4e48\u4e00\u4e2a\u7c7b\u662f\u8fd9\u4e48\u5199\u7684\uff1a<\/p>\n<pre><code>class dot { int speed; dot(int i ) } dot::dot(int i ){ speed = i; } <\/code><\/pre>\n<p>\u7136\u540e\u6bd4\u5982\u6211\u8981\u5b9e\u4f8b\u5316\u5b83\u7684\u65f6\u5019\u6211\u53d1\u73b0\u662f\u9700\u8981\u8fd9\u4e48\u5199\uff1a<\/p>\n<pre><code>dot dottest(1); <\/code><\/pre>\n<p>\u5426\u5219\u597d\u50cf\u4ed6\u662f\u6ca1\u6709\u529e\u6cd5\u88ab\u521d\u59cb\u5316\u7684\uff1f \u4f46\u662f\u5b9e\u9645\u95ee\u9898\u662f\uff0c\u6211\u5728 OF \u4e2d\u5b83\u662f\u5e26 setup \u548c draw \u51fd\u6570\u7684\u3002 \u901a\u5e38\u60c5\u51b5\u4e0b\u5982\u679c\u6211\u60f3\u5728 setup \u4e2d\u521d\u59cb\u5316\u8fd9\u4e2a\u7c7b\uff0c\u7136\u540e\u5728 draw \u51fd\u6570\u4e2d\u5faa\u73af\u8fd0\u884c\u5b83\u7684\u8bdd\uff0c\u6211\u5fc5\u987b\u8981\u628a\u8fd9\u4e2a\u7c7b\u58f0\u660e\u5728\u51fd\u6570\u5916\uff0c\u4f46\u6211\u53ea\u60f3\u5728 setup \u4e2d\u6784\u9020\u5b83\uff0c\u4f46\u76ee\u524d\u597d\u50cf\u6211\u6d4b\u8bd5\u4e86\u597d\u51e0\u6b21\u90fd\u4e0d\u884c\u3002 \u6709\u6ca1\u6709\u529e\u6cd5\u5148\u58f0\u660e\u7136\u540e\u5728\u5b9a\u4e49\u5462\uff1f \u6211\u67e5\u5230\u4e86\u5173\u4e8e&lt;extern&gt;\u7684\u7528\u6cd5\uff0c\u4f46\u662f\u5b83\u4f3c\u4e4e\u5e76\u4e0d\u662f\u6211\u60f3\u8981\u7684\u3002\u56e0\u4e3a\u6211\u672c\u8d28\u4e0a\u8fd8\u662f\u5728\u4e00\u4e2a cpp \u6587\u4ef6\u91cc\u9762\u53bb\u58f0\u660e\u5b83\u3002 \u8fd8\u6709\u4e00\u79cd\u60c5\u51b5\u662f\u5982\u679c\u5728 h \u6587\u4ef6\u5b9a\u4e49\uff0c\u5728 cpp \u6587\u4ef6\u4e2d\u4e5f\u53ef\u4ee5\u8c03\u7528\u3002\u4f46\u53ea\u8981\u662f\u6784\u9020\u5668\u5e26\u4e86\u53c2\u6570\u7684\uff0c\u5728 h \u6587\u4ef6\u4e2d\u597d\u50cf\u5c31\u6ca1\u6709\u529e\u6cd5\u5f88\u597d\u7684\u5b9a\u4e49\u8fd9\u4e2a\u5bf9\u8c61\u3002 \u6211\u4e4b\u6240\u4ee5\u6709\u8fd9\u4e2a\u7591\u95ee\u662f\u56e0\u4e3a\uff0c\u5728 processing \u4e2d\uff0c\u5b9e\u4f8b\u5316\u53ef\u4ee5\u8fd9\u4e48\u5199\uff1a<\/p>\n<pre><code>FlowField flowfield; void setup() { flowfield = new FlowField(10); } void draw(){ } <\/code><\/pre>\n<p>\u6211\u67e5\u4e86\u4e00\u4e0b C++\u548c java \u7684 new \u7684\u533a\u522b\uff0c\u8fd8\u6709\u58f0\u660e\u548c\u5b9a\u4e49\u7684\u533a\u522b\uff0c\u672c\u6765\u7528\u7684\u597d\u597d\u7684\u73b0\u5728\u8d8a\u770b\u8d8a\u61f5\u3002\u6240\u4ee5\u5982\u679c\u6211\u60f3\u6a21\u4eff\u4e0a\u9762 processing \u8fd9\u4e48\u7684\u5199\u6cd5\uff0c\u6211\u5728 C++\u4e2d\u5e94\u8be5\u5982\u4f55\u5b9e\u73b0\u5462\uff1f \u6211\u77e5\u9053 C++\u662f\u6709\u9ed8\u8ba4\u6784\u9020\u5668\u7684\uff0c\u6211\u4ee5\u524d\u7684\u5199\u6cd5\u662f\u81ea\u5df1\u989d\u5916\u5199\u4e00\u4e2a\u51fd\u6570\u53bb\u521d\u59cb\u5316\u7c7b\u91cc\u9762\u7684\u53d8\u91cf\u3002\u4f46\u662f\u524d\u6bb5\u65f6\u95f4\u7a81\u53d1\u5947\u60f3\u60f3\u7528\u4e00\u4e0b\u6784\u9020\u5668\uff0c\u7ed3\u679c\u5c31\u50bb\u773c\u4e86\u3002\u5173\u4e8e C++\u58f0\u660e\u548c\u5b9a\u4e49\u7684\u4e00\u4e9b\u76f8\u5173\u7684\u4ecb\u7ecd\u6211\u4e5f\u770b\u4e86\uff0c\u4f46\u8fd8\u662f\u5904\u4e8e\u4f3c\u61c2\u975e\u61c2\u7684\u72b6\u6001\u3002\u6c42\u5927\u5bb6\u6307\u6761\u660e\u8def\u3002\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>10<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1197154\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : InkStone <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u662f\u4f60\u81ea\u5df1\u5199\u7684\u7c7b\uff0c\u4f60\u53ef\u4ee5\u5199\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u6784\u9020\u5668\uff0c\u52a0\u4e0a\u4e00\u4e2a\u5305\u542b\u4e86\u771f\u6b63\u521d\u59cb\u5316\u903b\u8f91\u7684 init \u51fd\u6570\u3002<\/p>\n<p>\u5982\u679c\u662f\u522b\u4eba\u5199\u7684\u7c7b\uff0c\u8003\u8651\u4e0b\u7528\u4e00\u4e2a\u5355\u4f8b\u7c7b\u6765\u5305\u88c5\u4e00\u4e0b\u8fd9\u4e2a\u5bf9\u8c61\uff0c\u6765\u5b9e\u73b0\u4f60\u60f3\u8981\u7684\u5ef6\u8fdf\u52a0\u8f7d\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1197155\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Waihinchan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @InkStone \u55ef\u55ef \u611f\u8c22 \u5176\u5b9e\u603b\u4f53\u6211\u4e5f\u660e\u767d\u6709\u5f88\u591a\u65b9\u6cd5\u53ef\u4ee5\u89c4\u907f\u8fd9\u4e2a\u95ee\u9898\u3002\u5176\u5b9e\u662f\u6211\u6709\u70b9\u94bb\u725b\u89d2\u5c16\u4e86\uff0c\u56e0\u4e3a\u6211\u672c\u6765\u4e0d\u662f\u5f88\u7cfb\u7edf\u5730\u5b66\u4e60\u8fc7 C++\uff0c\u611f\u89c9\u5b66\u5230\u540e\u9762\u6df1\u5165\u7684\u6709\u4e00\u4e9b\u6982\u5ff5\u5c31\u5f00\u59cb\u6a21\u7cca\u548c\u6df7\u6dc6\u4e86\u3002<br \/>\u53e6\u5916\u60f3\u95ee\u4e00\u4e0b\uff1a\u60a8\u56de\u590d\u7684\u5173\u4e8e\u8fd9\u4e2a\u8f7b\u91cf\u7ea7\u7684\u6784\u9020\u5668\uff0c\u6211\u662f\u5426\u53ef\u4ee5\u7406\u89e3\u4e3a\u771f\u6b63\u53d1\u6325\u4f5c\u7528\u7684\u8fd8\u662f\u81ea\u5df1\u5199\u7684 init \u51fd\u6570\uff0c\u800c\u4ed6\u6784\u9020\u5668\u672c\u8eab\u53ef\u4ee5\u76f4\u63a5\u7f3a\u7701\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1197156\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : stackexplode <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             class A {<br \/>public:<br \/> A() = default;<br \/> Initialize(int speed) {speed_ = speed;}<br \/>private:<br \/> int speed_;<br \/>}<\/p>\n<p>A a;<br \/>a.Initialize(1);<\/p>\n<p>=======================<\/p>\n<p>class B {<br \/>public:<br \/> B(int speed) : speed_(speed) {}<br \/>private:<br \/> int speed_;<br \/>}<\/p>\n<p>std::unique_ptr&lt;B&gt; b;<\/p>\n<p>b = std::make_unique&lt;B&gt;(1);                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1197157\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Waihinchan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @stackexplode \u611f\u8c22\u56de\u590d\uff01 classA \u7684\u6211\u770b\u61c2\u4e86 classB \u7684\u6211\u518d\u6d88\u5316\u6d88\u5316 \u975e\u5e38\u611f\u8c22\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1197158\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : stackexplode <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Waihinchan B* b; b = new B(1); \u4e5f\u53ef\u4ee5\uff0c\u4e00\u6837                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1197159\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528\u6307\u9488\u5427\uff0csetup \u91cc\u9762 new \u7136\u540e\u8fd4\u56de\u5230\u5916\u9762\uff0c\u518d\u4f20\u9012\u8fdb draw \u3002<br \/>\u6216\u8005\u7528 std::optional \u4e5f\u884c\uff0c\u76f8\u6bd4\u4e4b\u4e0b\u66f4\u5b89\u5168 (\u4e0d\u4f1a\u6709\u5fd8\u8bb0 delete \u7684\u95ee\u9898)\uff0c\u4e0d\u9700\u8981\u52a8\u6001\u5206\u914d\u5185\u5b58\u3002<br \/>https:\/\/zh.cppreference.com\/w\/cpp\/utility\/optional                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1197160\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Wirbelwind <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6709\u7528\u6237\u5b9a\u4e49\u7684\u6784\u9020\u51fd\u6570\u65f6\uff0c\u7f16\u8bd1\u5668\u4e0d\u4f1a\u751f\u6210\u5176\u4ed6\u6784\u9020\u51fd\u6570\u3002<br \/>\u6ca1\u6709\u7528\u6237\u5b9a\u4e49\u7684\u6784\u9020\u51fd\u6570\u65f6\uff0c\u7f16\u8bd1\u5668\u770b class \u91cc\u9762\u6210\u5458\u53d8\u91cf\u7c7b\u578b\u6765\u5224\u65ad\u662f\u5426\u9700\u8981\u751f\u6210\u6784\u9020\u51fd\u6570\uff0c\u56e0\u4e3a\u666e\u901a\u5185\u7f6e\u7c7b\u578b\u5982 char,int,long long \u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u62f7\u8d1d\u503c\u6765\u5b8c\u6210\u3002\u5982\u679c\u6709\u5b9a\u4e49\u4e86\u6784\u9020\u51fd\u6570\u7684 class\uff0c\u6bd4\u5982\u8bf4 std::string\uff0c\u4f1a\u751f\u6210\u4e00\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u8fd9\u4e2a\u6784\u9020\u51fd\u6570\u91cc\u9762\u4f1a\u9012\u5f52\u8c03\u7528 std::string \u7684\u6784\u9020\u51fd\u6570\u3002<\/p>\n<p>\u5dee\u4e0d\u591a\u662f\u8fd9\u6837\u3002<\/p>\n<p>dot()=default;<\/p>\n<p>dot(int i )\u524d\u9762\u52a0\u4e00\u53e5\u8fd9\u4e2a\u5c31\u53ef\u4ee5\u4e86\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1197161\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Wirbelwind <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd8\u6709\u4e00\u79cd\u5199\u6cd5\u662f\u4f7f\u7528 placement new \u6765\u7533\u8bf7\u4e00\u5b9a\u7684\u5185\u5b58\uff0c\u4f46\u662f\u4e0d\u8fdb\u884c\u6784\u9020\u3002<\/p>\n<p>\u5728\u9700\u8981\u8fd9\u5757\u5185\u5b58\u7684\u65f6\u5019\u8c03\u7528\u76f8\u5173\u6784\u9020\u51fd\u6570\uff0c\u4e0d\u9700\u8981\u7684\u65f6\u5019\u8c03\u7528\u6790\u6784\u51fd\u6570\u3002<\/p>\n<p>\u4e0d\u8fc7\uff0c\u4e0d\u9700\u8981\u8fd9\u5757\u5185\u5b58(\u4e0d\u518d\u4f7f\u7528 new \u7684\u5bf9\u8c61)\u90fd\u662f\u9700\u8981 delete \u8c03\u7528\u7684                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1197162\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Waihinchan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ysc3839 \u611f\u8c22\u56de\u590d\uff5e\u73b0\u5728\u6211\u57fa\u672c\u4e0a\u638c\u63e1\u4e86\u6307\u9488\u7684\u7528\u6cd5 \u5176\u5b9e\u5173\u4e8e delete \u7684\u95ee\u9898\u6211\u4e5f\u67e5\u9605\u4e86\u4e00\u4e0b \u5e94\u8be5\u662f\u53ea\u8981\u8fdb\u7a0b\u7ed3\u675f\u4e86\u5185\u5b58\u8fd8\u662f\u4f1a\u91ca\u653e\u6389\u7684\u5427\uff1f\u6211\u4e3b\u8981\u505a\u7684\u662f\u4e00\u4e9b\u5c55\u793a\u6027\u7684\u7a0b\u5e8f \u611f\u89c9\u624b\u52a8\u91ca\u653e\u5bf9\u4e8e\u6211\u8fd9\u4e2a\u95ee\u9898\u5e76\u4e0d\u4f1a\u662f\u4e00\u4e2a\u5f88\u5927\u7684\u963b\u788d XD                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1197163\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : daimon2k <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             std::unique_ptr \u4e0d\u9700\u8981\u624b\u52a8\u91ca\u653e\u3002\u5176 dtor \u4f1a\u81ea\u52a8 delete \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u60f3\u8bf7\u6559\u4e00\u4e2a C++ \u5173\u4e8e\u521d\u59cb\u5316\u7c7b\u65f6&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\/94233"}],"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=94233"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/94233\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=94233"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=94233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}