Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7611633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:42:37+00:00 2026-05-31T01:42:37+00:00

StackOverflow. My first post here. I’ve come to D from C++ and MFC, which

  • 0

StackOverflow. My first post here.
I’ve come to D from C++ and MFC, which i’m using in my job – not only GUI stuff, but many MFC’s macro(DECLARE_DYNCREATE, etc.) and CObject class.
How i saw, in D we have std.Object class with factory method.

So, how to correctly rewrite this C++ code in D? if it is possible, of course.

class CPerson : public CObject 
{
    DECLARE_DYNAMIC( CPerson )
    // other declarations
};
IMPLEMENT_DYNAMIC( CPerson, CObject )
void DoSmthWithObject(const CObject* pObj)
{
    CPerson* pPerson = dynamic_cast<CPerson*>(pObj);
    ASSERT_VALID(pPerson);
    // Work with out CPerson object.
}

// Somethere in code create our CObject...
CObject* pMyObject = new CPerson;

// .. and do some strange things with it.
DoSmthWithObject(pMyObject);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:42:38+00:00Added an answer on May 31, 2026 at 1:42 am

    Downcasts are already runtime-checked in D. Attempting to perform an invalid downcast will result in a null reference.

    class A { }
    class B : A { }
    class C { }
    
    unittest
    {
        A a = new A();
        Object o = a;               // upcasts are implicit
        assert(o !is null);         // OK, all classes implicitly descend from Object
        assert(cast(A)o !is null);  // OK, same class
        assert(cast(B)o is null);   // Not allowed, B is subclass of A
        assert(cast(B)a is null);   // Ditto
        assert(cast(C)o is null);   // Not allowed, C is unrelated to A
        assert(cast(C)a is null);   // Ditto
        assert(cast(C)cast(void*)a !is null); // Use intermediate cast to
                                              // void* to bypass runtime checks
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post here in StackOverflow. I am not a newbie to
this is my first post here on stackoverflow and am very impressed by the
Frequent visitor but first post here on StackOverflow, I'm hoping that you guys might
this is my first post here on StackOverflow and I'm quite excited about it
this is my first post on stackoverflow. Hopefully I am not disturbing anybody... :)
this is my first post on stackoverflow. I hope my question is not to
This is my first post here on Stackoverflow, though over the years I've been
First look at this url: https://stackoverflow.com/questions/tagged/xoxoxo/ This directory does not exists but somehow stackoverflow
this is my first question to stackoverflow so here it goes... I use cruise
I have found here on stackoverflow a method to extend django's built-in authentication using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.