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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:17:09+00:00 2026-05-24T13:17:09+00:00

the following are 2 of weak_ptr’s constructors: http://msdn.microsoft.com/en-us/library/bb982126.aspx weak_ptr(const weak_ptr&); template<class Other> weak_ptr(const weak_ptr<Other>&);

  • 0

the following are 2 of weak_ptr’s constructors:
http://msdn.microsoft.com/en-us/library/bb982126.aspx

weak_ptr(const weak_ptr&);

template<class Other>
weak_ptr(const weak_ptr<Other>&);

actual code (from memory):

weak_ptr(const weak_ptr& _Other)
{   // construct weak_ptr object for resource pointed to by _Other
    this->_Resetw(_Other);
}

template<class _Ty2>
weak_ptr(const weak_ptr<_Ty2>& _Other,
         typename enable_if<is_convertible<_Ty2 *, _Ty *>::value,
         void *>::type * = 0)
{   // construct weak_ptr object for resource pointed to by _Other
    this->_Resetw(_Other);
}

Q1: Why is the top copy constructor even there? It looks like the bottom one accounts for every case (including the top one). Does it even get called? and if they didn’t include it would the bottom one take it’s place?

Q2: What’s going on with the second argument of the bottom (templated) constructor. I think I understand the SFINAE aspect, but I don’t understand why there is an extra * after ::type

  • 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-24T13:17:10+00:00Added an answer on May 24, 2026 at 1:17 pm

    Q1) If you don’t write a copy constructor, the compiler will generate one for you, which wouldn’t be what you want. Templated conversion constructors don’t count.

    Q2) Remember that shared_ptr<T> is like a T*, convertibility must be checked at the level of pointers. If T* is convertible to U* then you should be able to assign one to the other. Think of pointers-to-base. [Sorry, that wasn’t what you asked.] The final argument type just needs to exist, but also we don’t want to have to specify the argument itself. A universal way of making up a type for which we can also provide a default argument is a pointer. In short, we need to make the function depend on a type that may or may not exist, but without actually requiring the user to know about this.

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

Sidebar

Related Questions

Following my question regarding a .NET YAML Library ... as there doesn't seem to
Following this question: Good crash reporting library in c# Is there any library like
Following techniques from 'Modern C++ Design', I am implementing a persistence library with various
Let me give you the following example: Imagine you have a window class which
Imagine I have the following situation: Test1.java import java.lang.ref.WeakReference; public class Test1 { public
Imagine the following situation: class IAlarm : public boost::enable_shared_from_this<IAlarm> { boost::shared_ptr<IAlarm> getThisPointerForIAlarm() { return
I want to have the following class structure: #include <tr1/memory> class Interface; class Impl;
I have the following XML code <class name=ContentStreamer> <method name=sendAudio> <criteria>medium</criteria> </method> <method name=sendVideo>
I have the following functor: class ComparatorClass { public: bool operator () (SimulatedDiskFile *
Is the following a good way of describing ownership intent (without using shared_ptr?) class

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.