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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:15:03+00:00 2026-06-14T02:15:03+00:00

I’m going to omit quite bit of code because these are some rather large

  • 0

I’m going to omit quite bit of code because these are some rather large objects, and my question really just concerns the operation of std::make_shared . I have an object in namespace SYNC called called D3D11Shader. This has a static function called,

SYNC::D3D11Shader * SYNC::D3D11Shader::CreateInstance(const std::string & s)

which will take a string index and return a pointer to an instance of a shader that is derived from SYNC::D3D11Shader. At one point i started using smart pointers to automate deallocation of these within the vector that held all these shaders. However, when i go to do this,

 std::shared_ptr<SYNC::D3D11Shader> shaderPtr;
 // ... verification of index and other initialization happens here
 // so i am unable to initialize it in it's constructor
 shaderPtr = std::make_shared<SYNC::D3D11Shader>(SYNC::D3D11Shader::CreateShader(shaderName));

the compiler errors saying that i am trying to instanciate an instance of D3D11Shader in this line which is an abstract class. I thought all make_shared did was return an instance of std::shared_ptr. The CreateInstance function never tries to make an instance of this class, just objects that derive and implement it. I was not getting this error before using this function and the smart pointers. Does anyone know what’s going on here?

  • 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-14T02:15:04+00:00Added an answer on June 14, 2026 at 2:15 am

    If you can’t use the constructor of shared_ptr, use its reset member function to give it ownership of a new object:

    std::shared_ptr<SYNC::D3D11Shader> shaderPtr;
    shaderPtr.reset(SYNC::D3D11Shader::CreateShader(shaderName));
    

    The reason make_shared<T> is not appropriate for this situation is because it constructs a new T, forwarding its arguments to its constructor. You’ve already constructed an object, though, so you just want to give ownership to your shared pointer.

    I highly recommend not returning a raw pointer from CreateShader though. You’re relying on the caller of CreateShader to know to either wrap it up in a smart pointer or call delete on it. You’d be better off returning a unique_ptr directly, to pass ownership to the client, and then they can make a shared_ptr out of it if they like. See the following:

    std::unique_ptr<SYNC::D3D11Shader> uniquePtr(SYNC::D3D11Shader::CreateShader(shaderName));
    // If you want a shared_ptr:
    std::shared_ptr<SYNC::D3D11Shader> sharedPtr(std::move(uniquePtr));
    

    Or simply:

    std::shared_ptr<SYNC::D3D11Shader> sharedPtr = SYNC::D3D11Shader::CreateShader(shaderName);
    

    If you’re going to use smart pointers, use them. 🙂

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.