{"id":99,"date":"2012-06-19T14:33:27","date_gmt":"2012-06-19T05:33:27","guid":{"rendered":"http:\/\/soundengine.jp\/wordpress\/tips\/?p=99"},"modified":"2014-02-06T23:42:41","modified_gmt":"2014-02-06T14:42:41","slug":"%e3%83%98%e3%83%83%e3%83%80%e3%83%bc%e3%81%a7static%e3%80%81const%e3%83%a1%e3%83%b3%e3%83%90%e3%83%bc%e5%a4%89%e6%95%b0%e3%81%ae%e5%88%9d%e6%9c%9f%e5%8c%96","status":"publish","type":"post","link":"https:\/\/soundengine.jp\/wordpress\/tips\/tutorial\/99\/","title":{"rendered":"\u30d8\u30c3\u30c0\u30fc\u3067static\u3001const\u30e1\u30f3\u30d0\u30fc\u5909\u6570\u306e\u521d\u671f\u5316"},"content":{"rendered":"<p>\u901a\u5e38\u30bd\u30fc\u30b9(CPP)\u30d5\u30a1\u30a4\u30eb\u3067static\u30e1\u30f3\u30d0\u30fc\u5909\u6570\u3084const\u30e1\u30f3\u30d0\u30fc\u5909\u6570\u306e\u521d\u671f\u5316\u3092\u884c\u3046\u304c\u3001\u30d8\u30c3\u30c0\u30fc\u30d5\u30a1\u30a4\u30eb\u5185\u3067\u521d\u671f\u5316\u3057\u305f\u3044\u6642\u304c\u3042\u308b\u3002\u305d\u3093\u306a\u6642\u3069\u3046\u3059\u308b\u304b\u306eTips\u3002<\/p>\n<p><!--more--><\/p>\n<h2 id=\"content_1_0\">\u5931\u6557\u4f8b  <a class=\"anchor_super\" id=\"j1f9f9d6\" href=\"http:\/\/soundengine.jp\/backend\/?services%2Ftips%2F2007-02-16#j1f9f9d6\" title=\"j1f9f9d6\"> <\/a><\/h2>\n<p>C++\u3067\u6b21\u306e\u3088\u3046\u306b\u521d\u671f\u5316\u3067\u304d\u308c\u3070\u4e00\u756a\u3044\u3044\u306e\u3060\u304c\u305d\u308c\u306f\u3067\u304d\u306a\u3044\u3002(private,public\u8a18\u8ff0\u304c\u9762\u5012\u306a\u306e\u3067class\u3067\u306f\u306a\u304fstruct\u3067)<\/p>\n<pre>struct Test\r\n{\r\n    static string static_member = \"hoge\";\r\n    const string const_member = \"hoge\";\r\n};<\/pre>\n<p>\u3053\u308c\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u3068\u4e21\u8005\u306b\u5bfe\u3057\u6b21\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u73fe\u308c\u308b\u3002<\/p>\n<blockquote>\n<p class=\"quotation\">\u30a8\u30e9\u30fc\t1\terror C2864: &#8216;Test::static_member&#8217; : \u30b9\u30bf\u30c6\u30a3\u30c3\u30af const \u6574\u6570\u30c7\u30fc\u30bf \u30e1\u30f3\u30d0\u4ee5\u5916\u3092\u30af\u30e9\u30b9\u5185\u3067\u521d\u671f\u5316\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093<\/p>\n<\/blockquote>\n<p>\u307e\u305f\u3001const\u306e\u5834\u5408\u306b\u306f<\/p>\n<pre>struct Test\r\n{\r\n    const string const_member;\r\n};\r\n\r\nstring Test::const_member( \"hoge\" );<\/pre>\n<p>\u3053\u3093\u306a\u66f8\u304d\u65b9\u3092\u3057\u3066\u3082\u30b3\u30f3\u30d1\u30a4\u30e9\u306b\u6012\u3089\u308c\u308b\u3002<\/p>\n<blockquote>\n<p class=\"quotation\">error C2761: &#8216;const std::string Test::const_member&#8217; : \u30e1\u30f3\u30d0\u95a2\u6570\u306e\u518d\u5ba3\u8a00\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<\/blockquote>\n<p>\u307e\u305f\u3069\u3053\u304b\u3067static\u5909\u6570\u3092\u3053\u306e\u3088\u3046\u306b\u521d\u671f\u5316\u3059\u308b\u3068\u30ea\u30f3\u30ab\u3067\u30ea\u30f3\u30af\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3002(\u30d8\u30c3\u30c0\u30fc\u3092\u591a\u91cd\u306binclude\u3057\u3066\u308b\u6642)<\/p>\n<pre>struct Test\r\n{\r\n    static string static_member;\r\n};\r\n\r\nstring Test::static_member( \"hoge\" );<\/pre>\n<blockquote>\n<p class=\"quotation\">\u30a8\u30e9\u30fc\t1\terror LNK2005: &#8220;public: static class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; Test::static_member&#8221; (?static_member@Test@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) \u306f\u65e2\u306b Test.obj \u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002\thoge.obj<\/p>\n<\/blockquote>\n<p>\u3053\u3093\u306a\u98a8\u306b\u6012\u3089\u308c\u3066\u3057\u307e\u3046\u3002<\/p>\n<div class=\"jumpmenu\">\n<\/div>\n<h2 id=\"content_1_1\">\u6210\u529f\u4f8b  <a class=\"anchor_super\" id=\"sd46e40e\" href=\"http:\/\/soundengine.jp\/backend\/?services%2Ftips%2F2007-02-16#sd46e40e\" title=\"sd46e40e\"> <\/a><\/h2>\n<p>const\u30e1\u30f3\u30d0\u30fc\u5909\u6570\u306b\u5bfe\u3057\u3066\u306f\u5f53\u7136\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u521d\u671f\u5316\u3092\u3059\u308b\u3068\u3044\u3046\u5f62\u3067\u89e3\u6c7a\u3067\u304d\u308b\u3002static\u30e1\u30f3\u30d0\u30fc\u5909\u6570\u306b\u5bfe\u3057\u3066\u306f\u3001__declspec( selectany )\u3067\u89e3\u6c7a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<p><a href=\"http:\/\/msdn2.microsoft.com\/ja-jp\/library\/dabb5z75%28vs.71,en-us%29.aspx\" rel=\"nofollow\">__declspec<\/a>\u306fMicrosoft\u7279\u6709\u306e\u4ed5\u69d8(Microsoft Specific)\u3068MSDN\u3067\u66f8\u304b\u308c\u3066\u3044\u308b\u901a\u308aVC++\u7279\u6709\u306e\u30b3\u30de\u30f3\u30c9\u3067\u3042\u308b\u3002<\/p>\n<p>\u3053\u308c\u3089\u3092\u3075\u307e\u3048\u3066\u4f8b\u3048\u3070\u3053\u3093\u306a\u611f\u3058\u3002<\/p>\n<pre>struct Test\r\n{\r\n    static string static_member;\r\n    const string const_member;\r\n\r\n    Test() : const_member( \"hoge\" ) {};\r\n};\r\n\r\n__declspec( selectany ) string Test::static_member( \"hoge\" );<\/pre>\n<p>\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u4e21\u8005\u3092\u89e3\u6c7a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<div class=\"jumpmenu\">\n<\/div>\n<h2 id=\"content_1_2\">static const int  <a class=\"anchor_super\" id=\"ed2bb9d6\" href=\"http:\/\/soundengine.jp\/backend\/?services%2Ftips%2F2007-02-16#ed2bb9d6\" title=\"ed2bb9d6\"> <\/a><\/h2>\n<p>\u30b9\u30bf\u30c6\u30a3\u30c3\u30af\u306aconst\u6574\u6570\u306b\u3064\u3044\u3066\u306f\u3001\u3069\u3046\u3084\u3089\u5ba3\u8a00\u90e8\u5206\u3067\u521d\u671f\u5316\u3067\u304d\u308b\u3088\u3046\u3060\u3002<\/p>\n<pre>struct Test\r\n{\r\n    static const int n = 0;\r\n};<\/pre>\n<p>\u305d\u3046\u3044\u3048\u3070\u95a2\u4fc2\u306a\u3044\u304c\u3001declspec\u306edecl\u3068\u3044\u3046\u306e\u306f\u306a\u3093\u3060\u308d\u3046\u304b\u3001\u3001\u3001Yahoo\u306e\u8f9e\u66f8\u3060\u3068dec\u30fbla\u30fbma\u30fbtion\u3001declamation\u3068\u3044\u3046\u306e\u304c\u5f15\u3063\u304b\u304b\u308b\u3002\u3053\u306e\u610f\u5473\u304c\u300c\u5287\u7684\u52b9\u679c\u3092\u306d\u3089\u3046\u6f14\u8aac\u300d\u3068\u306e\u3053\u3068\u3002\u5287\u7684\u52b9\u679c\u3092\u306d\u3089\u3046\u4ed5\u69d8\u3068\u3044\u3046\u5ba3\u8a00\u306a\u3093\u3060\u308d\u3046\u304b\u3001\u3001\u3001\u3068\u601d\u3063\u305f\u304c\u3088\u304f\u8003\u3048\u308c\u3070declare specification\u307f\u305f\u3044\u3053\u3068\u306a\u306e\u304b\u306a\u3001\u3001\u3001<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u5e38\u30bd\u30fc\u30b9(CPP)\u30d5\u30a1\u30a4\u30eb\u3067static\u30e1\u30f3\u30d0\u30fc\u5909\u6570\u3084const\u30e1\u30f3\u30d0\u30fc\u5909\u6570\u306e &hellip; <a href=\"https:\/\/soundengine.jp\/wordpress\/tips\/tutorial\/99\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-99","post","type-post","status-publish","format-standard","hentry","category-tutorial"],"_links":{"self":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/99","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":4,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":3376,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/99\/revisions\/3376"}],"wp:attachment":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}