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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:08:55+00:00 2026-05-16T00:08:55+00:00

Declarations of auto_ptr from C++ Standard Library namespace std { template <class Y> struct

  • 0

Declarations of auto_ptr from C++ Standard Library

namespace std {

template <class Y> struct auto_ptr_ref {};


template <class X>
class auto_ptr {
public:
    typedef X element_type;

    // 20.4.5.1 construct/copy/destroy:
    explicit           auto_ptr(X* p =0) throw();
                       auto_ptr(auto_ptr&) throw();
    template <class Y> auto_ptr(auto_ptr<Y>&) throw();

    auto_ptr&                      operator=(auto_ptr&) throw();
    template <class Y> auto_ptr&   operator=(auto_ptr<Y>&) throw();
    auto_ptr&                      operator=(auto_ptr_ref<X>) throw();

    ~auto_ptr() throw();

    // 20.4.5.2 members:
    X&     operator*() const throw();
    X*     operator->() const throw();
    X*     get() const throw();
    X*     release() throw();
    void   reset(X* p =0) throw();

    // 20.4.5.3 conversions:
                                auto_ptr(auto_ptr_ref<X>) throw();
    template <class Y> operator auto_ptr_ref<Y>() throw();
    template <class Y> operator auto_ptr<Y>() throw();
};

}

I don’t understand the purpose of this part:

template <class Y> struct auto_ptr_ref {};

Without declaring any variable, how can these be valid:

auto_ptr&                      operator=(auto_ptr_ref<X>) throw();

and these too:

auto_ptr(auto_ptr_ref<X>) throw();
    template <class Y> operator auto_ptr_ref<Y>() throw();

Edit: and also (I just notice) I don’t understand how the “operator” are used for the last two lines. Isn’t the syntax something like “return-type operatoroperand;”, where is the return type? operand?

  • 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-16T00:08:56+00:00Added an answer on May 16, 2026 at 12:08 am

    Google search for “auto_ptr_ref” reveals this detailed explanation.

    I don’t quite get that explanation, but looks like it is for the following. Without that trick you could pass an auto_ptr into a function that would get ownership of the object and assign your variable to a null pointer. With the extra class trick above you will get a compile error in such case.

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

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer We have the data and schema stored in xml and… May 16, 2026 at 12:04 pm
  • Editorial Team
    Editorial Team added an answer The easiest way is to first do a query to… May 16, 2026 at 12:04 pm
  • Editorial Team
    Editorial Team added an answer i think i understood you. you want to sort by… May 16, 2026 at 12:04 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a class like this: class Inner; class Cont { public: Cont(); virtual
Suppose the following code declarations: itcl::class ObjectA { private variable m_ownedObject private variable m_someVariable
I was going through the auto_ptr documentation on this link auto_ptr There is something
mmm, I have just a little confusion about multiple auto declarations in the upcoming
Is there a difference between these two declarations? Is one better practice? NSString* hello
I am trying to understand array declarations, constness, and their resulting variable types. The
Consider these classes: class Parent { int a; } class Child extends Parent {
I ran into a compiler error that didn't make much sense to me: #include
Is there a common way to express the usage of arguments in C++? I
I'm having trouble getting intellisense to auto-complete shared pointers for boost 1.40.0. (It works

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.