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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:12:31+00:00 2026-05-26T21:12:31+00:00

I have a parent class test with child classes that are sub-tests. When I

  • 0

I have a parent class test with child classes that are sub-tests. When I call test->run() I want to run all my sub tests. The code below does not work b.c. the child class is not recognized in the parent class.

using namespace std;
  class test
    {
    protected:
      short verbosity_;
    public:
      void setVerbosity(short v)
        {
        if((v==0 || v==1 || v==2)) 
          {
          verbosity_ = v;
          }
        else 
          {
          cout << " Verbosity Level Invalid " << endl;
          }
        }
      void run()
        {
        natives natives_1; // this does not work
      }
    };
  class natives : public test 
    {
    public:
      natives()
        {
        this->run();
        }
      void run()
       {
       testInts<short>();
       testInts<int>();
       testInts<long>();
       testInts<unsigned short>();
       testInts<unsigned int>();
       testInts<unsigned long>();
       }         
    protected:
      template<class T> void testFloats()
        {
        }
      template<class T> void testInts()
        {
        short passState, bitDepth;
        T failMax, pow2 = 1, minValue = 0, maxValue = 0, bitCount = 0, failValue = 0;  
        const char* a = typeid(T).name();
        bool signedType = ((*a == 't') || (*a == 'j') || (*a == 'm'));
        while(pow2 > 0)
          {
          pow2 *= 2;
          bitCount++;
          }
        maxValue = pow2-1;
        failValue = pow2;
        int native1 = bitCount;
        int native2 = sizeof(T)*8;
        int native3 = numeric_limits<T>::digits;  
        if( !signedType )
          {
          native1++;
          native3++;
          }       
        if(verbosity_>=1) cout << endl << "**********\n" << reportType(a) << "\n**********" << endl << endl;
        if ((native1 == native2) && (native1 == native3))
          {
          if(verbosity_>=1)cout << "Correlation:\t\tPass: " << native1 << endl ;
          if(verbosity_>=2)
          {
            cout << "--Algorithm:\t\t" << native1 << endl;
            cout << "--Sizeof:\t\t" << native2 << endl;
            cout << "--Reported:\t\t" << native3 << endl;
            cout << "----Max Value:\t\t" << maxValue << endl;
            cout << "----Max+1\t\t" << failValue << endl;
            } 
         else
            {
            }
          }
        else
          {
          cout << "Correlation:\t\tFail" << endl ;
          }
        }
      string reportType(const char* c1)
        { 
        string s1;
        switch(*c1)
          {
          case 't':
            s1 = "Unsigned short";
            break;
          case 'j':
            s1 = "Unsigned int";
            break;
          case 'm':
            s1 = "Unsigned long";
            break;
          case 's':
            s1 = "Short";
            break;
          case 'i':
            s1 = "Int";
            break;
          case 'l':
            s1 = "Long";
            break;
          default:
            s1 = "Switch failed";
          }
        return s1;
        }
};
  • 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-26T21:12:31+00:00Added an answer on May 26, 2026 at 9:12 pm

    Probably a better way to do it would be to make a pure virtual function called run in the test class, and then the tests of the subclass will implement it and those will be run when you call run on an instance of the subclass.

    For instance:

    class Test {
    public:
        virtual void run() = 0;
    
        void setVerbosity(short v) {
            if((v==0 || v==1 || v==2)) 
                verbosity_ = v;
            else
                cout << " Verbosity Level Invalid " << endl;
        }
    };
    
    class Natives : public Test {
    public:
        void run() {
            // do all the tests....
        }
    };
    

    Then you can do

    Natives n;
    n.run();
    

    And they will still be run when you do it through a Test* (or Test&):

    Test* t = new Natives;
    t->run(); // runs Natives::run
    

    You might also be able to use CRTP here but I think it’s unnecessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Django, when you have a parent class and multiple child classes that inherit
I have a MustInherit Parent class with two Child classes which Inherit from the
I have a parent and child class that both need to implement IDisposable .
I have a parent class which contains a child object. I am using set
I have a parent class and child class (inherited from parent). In the child
I have a Parent/Child object/mapping as follows: class Parent { int Id; string name;
New to FluentNHibernate =D I have a parent/children classes as follows: public class Parent
I have a private method def __pickSide(self): in a parent class that I would
I have two linqTOsql entities that has a parent and child relationship, one to
This code compiles but looks very strange. I have a typical and simple parent/child

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.