Base class undefined when including header file in .cpp file-Collection of common programming errors
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^ name;
int appearance;
property bool Flag
{
virtual bool get() sealed
{
return flag;
}
void set(bool value)
{
if (flag != value)
{
flag = value;
}
}
}
property String^ Name
{
virtual String^ get() sealed
{
return name;
}
void set(String^ value)
{
if (name != value)
{
name = value;
}
}
}
property int App
{
virtual int get() sealed
{
return appearance;
}
void set(int value)
{
if (appearance != value)
{
appearance = value;
}
}
}
}
Untill now all its good, but if I add a .cpp file to implement the 2 constructors, after I include “implementation.h” I get the following error:
Artist
: base class undefined
Any idee what I get this ? I am missing something, I am totally new to this C++/CLI.
-
Your C++/CLI project needs to reference your C# project, or the DLL built from the C# project. You wouldn’t see this error until you had something to compile in your C++/CLI project (i.e. a .cpp file).
In Visual Studio, right-click on the C++/CLI project and select
References
. Click theAdd New Reference...
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.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.
Originally posted 2013-11-27 12:26:40.