{"id":94,"date":"2013-02-15T07:37:40","date_gmt":"2013-02-15T07:37:40","guid":{"rendered":"http:\/\/digital-madness.in\/blog\/?p=94"},"modified":"2018-02-17T18:00:07","modified_gmt":"2018-02-17T18:00:07","slug":"c-incomplete-type-and-cannot-be-defined","status":"publish","type":"post","link":"http:\/\/digital-madness.in\/blog\/2013\/c-incomplete-type-and-cannot-be-defined\/","title":{"rendered":"C++: incomplete type and cannot be defined"},"content":{"rendered":"<p>A very confusing error just now:<br \/>\nerror: aggregate \u2018std::ofstream out\u2019 has incomplete type and cannot be defined<\/p><p>from simple code:<br \/>\nstd::ofstream out;<\/p><p>And the similar one:<br \/>\nerror: variable \u2018std::ofstream out\u2019 has initialiser but incomplete type<\/p><p>from this code:<br \/>\nstd::ofstream out(fname.c_str(),std::ios_base::app);<\/p><p>Using this didn&#8217;t help:<br \/>\n#include &lt;iostream&gt;<\/p><p>Using this also didn&#8217;t help:<br \/>\n#include &lt;ofstream&gt;<\/p><p>That was confusing me most, but now I see I&#8217;ve been getting &#8220;error: ofstream: No such file or directory&#8221; and I was missing it in the noise of other warnings and errors.<\/p><p>The solution was simple:<br \/>\n#include &lt;fstream&gt;<br \/>\nYes, a very simple solution, but google wasn&#8217;t helping. If it had been saying &#8220;ofstream is not a member of std&#8221; I&#8217;d have known I was missing a header file; a strange error message has you looking in other places. (I guess another std header file is doing a forward declaration for ofstream, which is why we get &#8220;incomplete type&#8221;.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A very confusing error just now: error: aggregate \u2018std::ofstream out\u2019 has incomplete type and cannot be definedfrom simple code: std::ofstream out;And the similar one: error: variable \u2018std::ofstream out\u2019 has initialiser but incomplete typefrom this code: std::ofstream out(fname.c_str(),std::ios_base::app);Using this didn&#8217;t help: #include &lt;iostream&gt;Using this also didn&#8217;t help: #include &lt;ofstream&gt;That was confusing me most, but now I&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","footnotes":""},"categories":[38],"tags":[13,23],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-cpp","tag-c","tag-incomplete-type-and-cannot-be-defined"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":4,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":98,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/posts\/94\/revisions\/98"}],"wp:attachment":[{"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}