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

  • Home
  • SEARCH
  • 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 7731615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:31:27+00:00 2026-06-01T06:31:27+00:00

I’ve been dealing with a frustrating problem recently. I have a lot of reflection

  • 0

I’ve been dealing with a frustrating problem recently. I have a lot of reflection code I’d like to hide in macros. These COMPONENT_x() macros are used to like so:

class ComponentBase : public IComponent
{
    COMPONENT(ComponentBase)
};

class ComponentDerived1 : public ComponentBase
{
    COMPONENT_DERIVED(ComponentDerived1, ComponentBase)
};

The above is completely valid. However, I would like a compile error to occur in this case:

class ComponentDerived2 : public ComponentDerived1
{
    COMPONENT_DERIVED(ComponentDerived2, ComponentBase)
    //                                   ^^^^^^^^^^^^^
    // This type claims to have a superclass of ComponentBase in the above macro,
    // but we really derive from ComponentDerived1.
    //
    // I want this to result in a compile error. 
};

That is, when I’m claiming that my super class (or my base class) is ComponentBase when my the super class is actually ComponentDerived1, I would ideally like a compile-time error.

The reason I cannot easily detect this case is that while my super class is ComponentDerived1, that class’ super is ComponentBase — and thus it is also one of my base classes. (I understand that ComponentDerived1 is-a ComponentBase, so maybe there is a better phrase to use than “base class.”)

There were some comments questioning why I want to do this. I’m using an optimized system of component generation which puts all objects of the same type into discrete buffers, so generating knowledge of class relationships is important if I want to have an API such as getComponentsThatImplement(ComponentDerived1::getType());.

I had hacked together one solution that works with g++:

class ComponentBase : public IComponent
{
    COMPONENT(ComponentBase)

protected:
    static void helperComponentBase(); // COMPONENT(ComponentBase)
};

class ComponentDerived1 : public ComponentBase
{
    COMPONENT_DERIVED(ComponentDerived1, ComponentBase)

private:
    using ComponentBase::helperComponentBase; // COMPONENT_DERIVED(..., ComponentBase)
};

class ComponentDerived2 : public ComponentDerived1
{
    COMPONENT_DERIVED(ComponentDerived2, ComponentBase)

private:
    using ComponentBase::helperComponentBase; // error: this function is already hidden
}

Unfortunately, clang with Xcode 4.3.2 seems to not support using in this way. I’ve check boost’s type traits library and don’t see anything useful. I am using C++11, so I can use modern constructs.

Any other clever ideas?

  • 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-06-01T06:31:29+00:00Added an answer on June 1, 2026 at 6:31 am

    You can exploit the fact that from a c’tor you cannot directly call your super’s super’s c’tor:

    enum PATERNITY_TEST_ENUM { PATERNITY_TEST }; 
    
    #define COMPONENT(CLASS) \
    public: CLASS(PATERNITY_TEST_ENUM) { } private:
    
    #define COMPONENT_DERIVED(CLASS, SUPER) \
    public: CLASS(PATERNITY_TEST_ENUM) : SUPER(PATERNITY_TEST) { } private:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.