Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling base constructor in c++ CLI

Tags:

.net

c++-cli

If I inherit from a base class and want to pass something from the constructor of the inherited class to the constructor of the base class, how do I do that?

For example,

If I inherit from the Exception class I want to do something like this:

in C# Language we do it like this:

public class CppDynamicSyntaxLanguage : DynamicOutliningSyntaxLanguage
{
  public CppDynamicSyntaxLanguage(string key, bool secure) :
   **base(key, secure)** {}
}

but how to do it in c++.net ? i try to do it like this :

public ref class CppDynamicSyntaxLanguage : public DynamicOutliningSyntaxLanguage 
{
public:
 CppDynamicSyntaxLanguage (String ^key, bool secure) : 
  **CppDynamicSyntaxLanguage(key,secure)** {};
}

but i got Error 'MyEditor::CppDynamicSyntaxLanguage' : illegal member initialization: 'CppDynamicSyntaxLanguage' is not a base or member

"Thank You"

like image 717
user572312 Avatar asked Jan 12 '11 07:01

user572312


2 Answers

The base class is named DynamicOutliningSyntaxLanguage, not CppDynamicSyntaxLanguage.

CppDynamicSyntaxLanguage (String ^key, bool secure) 
    : DynamicOutliningSyntaxLanguage(key,secure) { };
like image 154
James McNellis Avatar answered Oct 08 '22 23:10

James McNellis


Did you try:

class CppDynamicSyntaxLanguage: public DynamicOutliningSyntaxLanguage {
public:
    CppDynamicSyntaxLanguage(string key, bool secure):
        DynamicOutliningSyntaxLanguage(key, secure) {
    }
};

It would work in c++, don't know about .net. Assuming DynamicOutliningSyntaxLanguage has a constructor that consumes sting and bool.

like image 27
Artur Czajka Avatar answered Oct 08 '22 23:10

Artur Czajka