简体   繁体   中英

Base class undefined when including header file in .cpp file

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 (ie a .cpp file).

In Visual Studio, right-click on the C++/CLI project and select References . Click the Add 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM