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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:11:36+00:00 2026-05-17T17:11:36+00:00

Can you tell me what is wrong with this piece of code? I got

  • 0

Can you tell me what is wrong with this piece of code? I got asked this in an interview and I am not sure what’s wrong with it

tClass is a test class with a method printSomething that prints members of tClass.

tClass * A = new tClass();
f(A);
A->printSomething();

auto_ptr<tClass> * B = new tClass();
f(B);
B-> printSomething();

or what this is a trick question.

  • 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-17T17:11:36+00:00Added an answer on May 17, 2026 at 5:11 pm

    auto_ptr is a type of smart pointer that operates under the premise that exactly one party owns the pointer, and if that owning party goes out of scope, the pointer gets deleted.

    When you pass an auto_ptr to a function, you are “Giving” the function that pointer, and so you don’t have it anymore. when you dereference it, you get a null pointer behavior (which is undefined, of course).

    In order to get your code to compile, though, you have to change your definition of B a bit, it should be

    auto_ptr<tClass> B = new tClass;
    

    since auto_ptr is not a type (its a type template), and you don’t actually want a pointer to that type at all, since the class overloads those behaviors.

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

Sidebar

Related Questions

Can anyone tell what is wrong with this piece of code? template<class X> class
Can anyone tell me what's wrong with this code? class Dataset < ActiveRecord::Base has_many
Can anyone tell me what is wrong with this code? public abstract class BoardTestBean{
Can someone please tell me whats wrong with this code. I'm not getting complete
Specifically, can somebody tell me what is wrong with this piece of code. It
Can someone please tell me where I'm going wrong with this piece of code?
I'm not sure how to explain this but this piece of code bellow can
Can anyone tell me what's wrong with this piece of code? I can't seem
Can you tell me what's wrong with this piece of code? //bmp is a
Can someone tell me what is wrong with this code? <?php $user = $fgmembersite->UserFullName();

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.