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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:18:31+00:00 2026-06-04T05:18:31+00:00

Not sure if someone has already asked this, but I see a strange behavior

  • 0

Not sure if someone has already asked this, but I see a strange behavior here:

I’ve declared two classes, one base and one derived with just one virtual method display().

class A {
public:
    virtual void display() {
        cout << "base class" << endl;
    }
};

class B:public A {
public:
    void display() {
        cout << "derived class" << endl;
    }
};

Now, in main(), if I try to declare an auto_ptr of A and assign it a new instance of B,

int main() {
    auto_ptr<A> *a = (auto_ptr<A>*)new B();
    a->display();
}

I get this error on compiling:

“'class std::auto_ptr<A>' has no member named ‘display'”

Am I doing something wrong? Can someone explain the behavior?

  • 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-04T05:18:32+00:00Added an answer on June 4, 2026 at 5:18 am

    You are creating a pointer to an auto_ptr. An auto_ptr is an object that works like a pointer, so you don’t need to add a *.

    You probably want:

    auto_ptr<A> a(new B());
    a->display();
    

    Although I must recomment either Boost’s smart pointers (scoped_ptr and shared_ptr) or C++11’s std::unique_ptr and std::shared_ptr.

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

Sidebar

Related Questions

Probably someone has already asked this question but I'm not sure what I'm looking
I am sure this has been asked already, but I have been trying all
Not sure if this is the correct Stack Exchange website but here goes.. A
Not sure whats going on here, or what could be the integer in this
Not sure if im just being stupid or something but here goes i work
Not sure how to ask this, but i'll give it a try: I have
Not sure if this is a big deal. But wondering why when the site
not sure what I'm missing here, but i keep getting the error. SQLSTATE[HY093]: Invalid
Perhaps something similar has already been asked, and sure, it's a nitpick... I have
I know this flavor of question has been asked multiple times, but I've spent

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.