开发者

Base class undefined when including header file in .cpp file

开发者 https://www.devze.com 2023-03-31 14:02 出处:网络
I have the following interface declared in C#: public interface ArtistInterface { bool Flag { get; set; }

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^ v开发者_StackOverflow社区alue)
        {
            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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消