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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:39:31+00:00 2026-05-30T05:39:31+00:00

I have come across a case as described below, and want to understand how

  • 0

I have come across a case as described below, and want to understand how this works. I have a class whose constructor expects another class as an argument. Then in code I see instead of passing that expected class’ object as an argument, instead another class’ object is passed (this class happens to be the base class for the expected class).

adding real code:

class s_api {
public:
};

class PB {
public:
    PB ( s_api *sa ) {}
};

class TValue : public s_api {
public:
    TValue () {}
};

int main() {
    TValue tvl;
    PB pb(tvl); //tvl is object of class TValue
}

How does this work)?

  • 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-30T05:39:32+00:00Added an answer on May 30, 2026 at 5:39 am

    This is the basis of polymorphism. Wherever you have something that expects an s_api * (i.e. a pointer to base class), you are free to pass a Tvalue * (i.e. a pointer to derived class).

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

Sidebar

Related Questions

I’m new to Selenium and I have come across a test case issue in
I have come across this problem in a calculation I do in my code,
Maybe some of you have come across this before.... I am opening files for
While analyzing some library code supplied by another company we have come across strange
I'm trying to figure out someone else's code and have come across this piece
I am looking for a good Tree data structure class. I have come across
I have come across the singleton pattern . I was unable to understand the
I have come across this situation. In the hash1 first column is the key
Today, I have come across a bug in my Zend Framework application. This is
I have an simple question (?) about SQL. I have come across this problem

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.