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 860593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:50:23+00:00 2026-05-15T08:50:23+00:00

I have a superclass which is defined in terms of a few internal types

  • 0

I have a superclass which is defined in terms of a few internal types it uses. Subclassing is performed as so:

template <class InternalType1, class InternalType2>
class Super 
{
    ...
}

class Sub : Super <interalTypeClass1, interalTypeClass2>
{ 
    ...
}

But when I want to write a function that takes a pointer to the superclass, this happens :

template <class InternalType1, class InternalType2>
void function(Super<InternalType1, InternalType2>* in) { ... }

The user really shouldn’t know anything about the inside classes, and should really just concern himself with the use of the function. Some of these template lists become very very large, and expecting the user to pass them every time is wasteful, in my opinion.

Any suggestions?

EDIT: The function needs to know the internal types in use, so unless there is a way to access template types at compile time, I think there is no solution?

Potential solution: Have each class do the following:

#define SubTemplateArgs <SubTypeName, SubInternalType1, SubInternalType2>

?

  • 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-15T08:50:24+00:00Added an answer on May 15, 2026 at 8:50 am
    template <class TInternal1, TInternal2>
    class Super {
        private:
            /*...*/
        public:
            typedef TInternal1 internal_type_1;
            typedef TInternal2 internal_type_2;
            /*...*/
    };
    
    typedef Super<int, char>    IntCharSuper;
    typedef Super<bool, char>   BoolCharSuper;
    
    class Sub1 : IntCharSuper {/*...*/};
    class Sub2 : IntCharSuper {/*...*/};
    class Sub3 : BoolCharSuper {/*...*/};
    
    
    /***
     * functionA (below) can only take a pointer to an object of a
     * class which inherits from IntCharSuper
     **/
    void functionA(IntCharSuper* in){
        IntCharSuper::internal_type_1 internal1_variable;
        IntCharSuper::internal_type_2 internal2_variable;
        // we now have 2 variables of the internal types...
    }
    
    /***
     * functionB (below) can take a pointer to an object of a class which inherits from any kind of Super, 
     * no matter what the template parameters of that Super are.
     * so functionB will work for types which inherit from 
     *    IntCharSuper, BoolCharSuper, Super<YourCustomType, void*>, or anything else for TInternal1 and TInternal2.
     **/
    template <class TSuper>
    void functionB(TSuper* in) {
        typename TSuper::internal_type_1 internal1_variable; /* typename is needed here */
        typename TSuper::internal_type_2 internal2_variable; /* typename is needed here */
        // we now have 2 variables of the internal types...
    }
    
    int main(int argc, const char* argv) {
            Sub1 s1;
            Sub2 s2;
            Sub3 s3;
            functionA(&s1);  //OK, s1 inherits IntCharSuper
            functionA(&s2);  //OK, s2 inherits IntCharSuper
            functionA(&s3);  //ERROR, s3 hasnt got IntCharSuper as parent
    
            functionB(&s2); //OK, s2 inherits from a class which defines internal_type_1 and internal_type_2
            functionB(&s3); //OK, s3 inherits from a class which defines internal_type_1 and internal_type_2
    
            return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done a few projects lately using a Database Object super class which
I have a class which I cant change (SuperClass) that has an interface for
I have defined a class which represents a tree structure GeographicalUnits = Ext.extend(Ext.tree.TreePanel, {
I have a superclass which instantiates my Sql class so all derived classes will
I have some classes which extends a superclass, and in the JSP I want
I have this object which is an instance of a superclass. I want to
I have a table in a DB (Postgres based), which acts like a superclass
I have an AbstractEntity class as superclass for all my entites that defines an
I want to have a function defined in a superclass that returns an instance
I have set of classes which inherit from a single super class: Super |

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.