{"id":1671,"date":"2022-08-30T15:18:28","date_gmt":"2022-08-30T15:18:28","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/base-class-undefined-when-including-header-file-in-cpp-file-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:18:28","modified_gmt":"2022-08-30T15:18:28","slug":"base-class-undefined-when-including-header-file-in-cpp-file-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/base-class-undefined-when-including-header-file-in-cpp-file-collection-of-common-programming-errors\/","title":{"rendered":"Base class undefined when including header file in .cpp file-Collection of common programming errors"},"content":{"rendered":"<p>I have the following interface declared in C#:<\/p>\n<pre><code>public interface ArtistInterface\n{\n    bool Flag { get; set; }\n\n    string Artist { get; set; }\n\n    int App { get; set; }\n}\n<\/code><\/pre>\n<p>And I want to implemented in C++\/CLI:<\/p>\n<p>implementation.h<\/p>\n<pre><code>public ref class Artist: public ArtistInterface\n{\n    Artist(String^ name);\n    Artist(String^ name, int number);\n\n    bool flag;\n    String^ name;\n    int appearance;\n\n    property bool Flag\n    {\n        virtual bool get() sealed\n        {\n            return flag;\n        }\n\n        void set(bool value)\n        {\n            if (flag != value)\n            {\n                flag = value;\n            }\n        }\n    }\n\n    property String^ Name\n    {\n        virtual String^ get() sealed\n        {\n            return name;\n        }\n\n        void set(String^ value)\n        {\n            if (name != value)\n            {\n                name = value;\n            }\n        }\n    }\n\n    property int App\n    {\n        virtual int get() sealed\n        {\n            return appearance;\n        }\n\n        void set(int value)\n        {\n            if (appearance != value)\n            {\n                appearance = value;\n            }\n        }\n    }\n}\n<\/code><\/pre>\n<p>Untill now all its good, but if I add a .cpp file to implement the 2 constructors, after I include &#8220;implementation.h&#8221; I get the following error:<\/p>\n<blockquote>\n<p><code>Artist<\/code>: base class undefined<\/p>\n<\/blockquote>\n<p>Any idee what I get this ? I am missing something, I am totally new to this C++\/CLI.<\/p>\n<ol>\n<li>\n<p>Your C++\/CLI project needs to reference your C# project, or the DLL built from the C# project. You wouldn&#8217;t see this error until you had something to compile in your C++\/CLI project (i.e. a .cpp file).<\/p>\n<p>In Visual Studio, right-click on the C++\/CLI project and select <code>References<\/code>. Click the <code>Add New Reference...<\/code> button. Choose the C# project (if in the same solution) or C# dll (if not in the same solution). See if the error goes away.<\/p>\n<p>Also, your original code has properties with virtual get() but non-virtual set(). Both have to be the same. Sounds like you want to make your set() virtual as well.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-27 12:26:40. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have the following interface declared in C#: public interface ArtistInterface { bool Flag { get; set; } string Artist { get; set; } int App { get; set; } } And I want to implemented in C++\/CLI: implementation.h public ref class Artist: public ArtistInterface { Artist(String^ name); Artist(String^ name, int number); bool flag; String^ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1671","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1671"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1671\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}