Re: C# inheritance broken?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Mike Schilling wrote:
<groups@xxxxxxxxxxxxx> wrote in message news:1170084841.336327.226140@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[...]
But you haven't shown a C++ solution either, since the cast in your example doesn't work.

If a constructor is added like in the following example, it will work. Think that was the intention of Tony.

class Document
{
public:
Document(){}
static Document Load() { return Document(); }
};

class MyDocument : public Document
{
public:
MyDocument() {}
MyDocument(Document& s) : Document(s) {}
static MyDocument Load() { return Document::Load(); }
};

int main(int argc, char* argv[])
{
MyDocument s = MyDocument::Load();
return 0;
}

Andre

.



Relevant Pages

  • Re: C# inheritance broken?
    ... if the class is declared as sealed or the only constructor it has is a ... | class MyDocument: public Document ... 2- It's declared private ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# inheritance broken?
    ... The Document class does have a public default constructor, ... an existing Document object ... | class MyDocument: public Document ... 2- It's declared private ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# inheritance broken?
    ... If a constructor is added like in the following example, ... static Document Load() ... class MyDocument: public Document ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# inheritance broken?
    ... If a constructor is added like in the following example, ... static Document Load() ... class MyDocument: public Document ...
    (microsoft.public.dotnet.languages.csharp)