开发者

Calling base constructor in 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 secu开发者_高级运维re) : 
  **CppDynamicSyntaxLanguage(key,secure)** {};
}

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

"Thank You"


The base class is named DynamicOutliningSyntaxLanguage, not CppDynamicSyntaxLanguage.

CppDynamicSyntaxLanguage (String ^key, bool secure) 
    : DynamicOutliningSyntaxLanguage(key,secure) { };


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜