0

I have logger.cs:

public abstract class LogProvider
{
    protected abstract void DoLog(LogEvent logEvent);
}

my_code.cpp

ref class DebugLogProvider : public LogProvider
{
public:

    virtual void DoLog(LogEvent logEvent)
    {
        Console::WriteLine(gcnew System::String("fsdfsdf")); 
    }
};

I got error:

error C2259: '`anonymous-namespace'::DebugLogProvider': cannot instantiate abstract class
message : 'void LogProvider::DoLog(LogEvent ^)': is abstract

How to override DoLog ?

1
  • Use the override keyword. Commented Mar 6, 2023 at 13:53

1 Answer 1

1

It seems the LogProvider class has a pure virtual function DoLog() that is declared as abstract without an implementation. Any derived class that inherits from LogProvider must implement DoLog().

In your DebugLogProvider class, you need to implement the DoLog() function to override the pure virtual function in the base class. e.g:

ref class DebugLogProvider : public LogProvider
{
public:
    virtual void DoLog(LogEvent^ logEvent) override
    {
        Console::WriteLine(gcnew System::String("fsdfsdf")); 
    }
};
Sign up to request clarification or add additional context in comments.

1 Comment

Ahhh Thanks! I haven't added ^ after type LogEvent in function definition. That is why it treated it as value but not ref. So signature of the function is different to what is defined in base class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.