Click here to Skip to main content
16,015,583 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionHow can I update my status-bar in MFC? Pin
Member 1503370431-Dec-20 21:03
Member 1503370431-Dec-20 21:03 
AnswerRe: How can I update my status-bar in MFC? Pin
Richard MacCutchan31-Dec-20 21:19
mveRichard MacCutchan31-Dec-20 21:19 
QuestionAdding references to WPF or WinForms in .NET 5 (from C++/CLI) Pin
John Schroedl18-Dec-20 5:11
professionalJohn Schroedl18-Dec-20 5:11 
AnswerRe: Adding references to WPF or WinForms in .NET 5 (from C++/CLI) Pin
John Schroedl18-Dec-20 7:34
professionalJohn Schroedl18-Dec-20 7:34 
Question“error:passing 'const std::vector<int>' as 'this' argument discards qualifiers [-fpermissive]” Pin
neuronphysics13-Dec-20 16:35
neuronphysics13-Dec-20 16:35 
Questionap alternate boundary pairs in matrix Pin
Doraemon Kids25-Nov-20 8:26
Doraemon Kids25-Nov-20 8:26 
AnswerRe: ap alternate boundary pairs in matrix Pin
Richard MacCutchan25-Nov-20 9:24
mveRichard MacCutchan25-Nov-20 9:24 
QuestionAbstract classes and factories Pin
Richard Andrew x6412-Sep-20 5:53
professionalRichard Andrew x6412-Sep-20 5:53 
I have two sets of classes, C++/CLI classes and native classes.

They are supposed to be counterparts of each other, used for passing messages & data between a managed module and a native module, with a mixed-mode module in between.

The CLI classes are set up thus: (You may have to meditate on this for a moment to see what I'm trying to do.)
C++
public ref class Managed_base abstract
{
    unsigned int _Data = 0;
    
    virtual Native_base* GetNativeObject(unsigned int data) = 0;
}

public ref class Managed_derived : Managed_base
{
    virtual Native_derived* GetNativeObject(unsigned int data) override
    {
        Native_derived* NativeObject = new Native_derived();
        NativeObject->_Data = data;

        return NativeObject;
    }
}
I'm trying to set it up so that if I call GetNativeObject on any managed derived class, it will return the corresponding derived native class.

That way I don't have to do any ugly casting when I call GetNativeObject.

But the compile error I get is, "Virtual function overriding with a covariant return type is not allowed in a managed class."

So my question is, is there any way to accomplish what I'm trying to do without having to cast the return type of the GetNativeObject method to the appropriate derived type?

Is there any pattern that does this?

EDIT:

I eventually decided to do away with the pure virtual method and the overriding methods in derived classes. I simply put a regular function into each derived class that returns the appropriate derived native class. It is not beautiful, but it works. Shucks | :-\

However, I would like to leave this question active, in case someone has any interesting ideas.



The difficult we do right away...
...the impossible takes slightly longer.


modified 12-Sep-20 16:49pm.

Questionsorce code grid line Pin
SADEGH20771-Aug-20 7:32
SADEGH20771-Aug-20 7:32 
AnswerRe: sorce code grid line Pin
Dave Kreskowiak1-Aug-20 8:41
mveDave Kreskowiak1-Aug-20 8:41 
QuestionCreating an OpenGL view on a Windows Form Pin
SADEGH207730-Jul-20 8:05
SADEGH207730-Jul-20 8:05 
QuestionOPENGL 4.6 Not responsive please help Pin
SADEGH207730-Jul-20 6:13
SADEGH207730-Jul-20 6:13 
AnswerRe: OPENGL 4.6 Not responsive please help Pin
Richard Andrew x6430-Jul-20 6:42
professionalRichard Andrew x6430-Jul-20 6:42 
QuestionTO OPENGL 4.6 Not responsive please help Pin
SADEGH207730-Jul-20 6:09
SADEGH207730-Jul-20 6:09 
QuestionI want to use this source code that you put, but with opengl 4.6 Does not run and gives an error Pin
SADEGH207730-Jul-20 5:36
SADEGH207730-Jul-20 5:36 
AnswerRe: I want to use this source code that you put, but with opengl 4.6 Does not run and gives an error Pin
Richard MacCutchan31-Jul-20 4:52
mveRichard MacCutchan31-Jul-20 4:52 
QuestionCreating an OpenGL view on a Windows Form Pin
SADEGH207730-Jul-20 3:54
SADEGH207730-Jul-20 3:54 
AnswerRe: Creating an OpenGL view on a Windows Form Pin
Richard MacCutchan30-Jul-20 4:15
mveRichard MacCutchan30-Jul-20 4:15 
Questionc++ program Pin
Member 148568768-Jun-20 2:31
Member 148568768-Jun-20 2:31 
AnswerRe: c++ program Pin
Eddy Vluggen8-Jun-20 3:01
professionalEddy Vluggen8-Jun-20 3:01 
GeneralRe: c++ program Pin
Member 148568768-Jun-20 4:27
Member 148568768-Jun-20 4:27 
GeneralRe: c++ program Pin
Eddy Vluggen8-Jun-20 5:13
professionalEddy Vluggen8-Jun-20 5:13 
GeneralRe: c++ program Pin
Member 148568768-Jun-20 5:23
Member 148568768-Jun-20 5:23 
GeneralRe: c++ program Pin
Richard MacCutchan8-Jun-20 5:34
mveRichard MacCutchan8-Jun-20 5:34 
GeneralRe: c++ program Pin
Member 148568768-Jun-20 5:51
Member 148568768-Jun-20 5:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.