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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:37:26+00:00 2026-06-14T19:37:26+00:00

The following code fails on MSVC11 with the error cannot convert parameter 1 from

  • 0

The following code fails on MSVC11 with the error

cannot convert parameter 1 from 'std::unique_ptr<DerivedClass>' to 'std::unique_ptr<BaseClass>' 

The code:

class BaseClass
{ };

class DerivedClass : public BaseClass
{ };

void MyFunction(std::unique_ptr<BaseClass> obj)
{ };

int main()
{
      auto ptr = std::unique_ptr<DerivedClass>(new DerivedClass);
      MyFunction(ptr);                 // fails, with error about cannot convert type
      // MyFunction(std::move(ptr));   // This will work
}

As pointed out in the answers the reason is std::move is missing, but the error message confused me enough to post the question, so I’ve updated it so anyone who is similarly confused has the best chance of finding the answer.

  • 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-14T19:37:27+00:00Added an answer on June 14, 2026 at 7:37 pm

    Your error has nothing to do with up or down casting. You are attempting to copy ptr, which is not allowed. If you pass std::move(ptr), the cast will be implicit and automatic, like a regular pointer.

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

Sidebar

Related Questions

The following code fails when the constructor parameter is declared with val Works: class
The following code fails with a 'Could not load type 'System.Xml.XmlDocument' from assembly' error:
The following code fails to run on Python 2.5.4: from matplotlib import pylab as
The following code fails to compile: class MyClass<T> : where T : MyClass <T>{}
Why the following code fails with: Error: class_a_jquery_objects[0].parent is not a function ? HTML:
The following code fails on a MISRA check. The concrete error message is: (MISRA-C:2004
I'm wondering why the following code fails to work: public static <T extends INode>
The following code fails to compile on g++ 4.6.1: template<class Base> struct GetBase {
The following code fails to compile with message: cannot instantiate type SymmetricKey SymmetricKey is
I have the following code: import java.util.*; public class SellTransaction extends Transaction { private

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.