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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:19:40+00:00 2026-05-28T08:19:40+00:00

Edit: The data is as follows typedef std::shared_ptr<T> Resource; typedef std::map<std::string, Resource> ResourceMap; This

  • 0

Edit:
The data is as follows

typedef std::shared_ptr<T> Resource;
typedef std::map<std::string, Resource> ResourceMap;

This is the function

const T& Get(const std::string& key)
{
    ResourceMap::iterator itr = mResources.find(key);
    return (itr != mResources.end()) ? itr->second : mDefault;

}

Error:

Error   1   error C2446: ':' : no conversion from 'sf::Texture' to 'std::tr1::shared_ptr<_Ty>'  d:\sanity\trunk\client\src\assetmanager.h   28

Also I’m creating an object like that :

AssetManager<sf::Texture> imgManager;

Okay, sorry for missing information, I was in a rush.

The only problem left is :

return (itr != mResources.end()) ? itr->second.get() : mDefault;

get() returns raw pointer and I need to return reference to what the shared_ptr is pointing.

How should I do that?

  • 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-28T08:19:40+00:00Added an answer on May 28, 2026 at 8:19 am
    Error   1   error C2446: ':' : no conversion from 'sf::Texture' to
    'std::tr1::shared_ptr<_Ty>' d:\sanity\trunk\client\src\assetmanager.h 28
    

    I guess your problem is that itr->second is of one type (Resource, if your std::map typedef is correct), while mDefault must be something other.

    The ternary operator cannot handle the two different types, so you must correct your code to be sure both items left and right of the : part of the ?: operator are of the same type (or compatible ones).

    So confirm this, I need:

    • the declaration of the Resource type
    • the declaration of the T type
    • the declaration of the mDefault member variable

    Edit

    Let’s assume you have something like:

    typedef std::shared_ptr<T> Resource;
    typedef std::map<std::string, Resource> ResourceMap;
    
    template <typename T>
    class AssetManager
    {
        const T& Get(const std::string& key)
        {
            ResourceMap::iterator itr = mResources.find(key);
            return (itr != mResources.end()) ? itr->second : mDefault;
        }
    
        ResourceMap mResources ;
        ??? mDefault ;
    
        // etc.
    } ;
    

    instanciated like:

    AssetManager<sf::Texture> imgManager;
    

    Now, I need the type of mDefault to continue.

    My guess: You MUST make sure your code is more like:

        const T& Get(const std::string& key) const
        {
            ResourceMap::const_iterator itr = mResources.find(key);
            return (itr != mResources.end()) ? *(itr->second) : *(mDefault);
        }
    
        ResourceMap mResources ;
        Resource mDefault ;
    

    As you want to return the Resource, not the shared_ptr of the Resource.

    Note that I added const keywords/prefix to be consistent with the const return

    Edit 2

    As you have:

        ResourceMap mResources ;
        T mDefault ;
    

    So I guess you should write:

        const T& Get(const std::string& key) const
        {
            ResourceMap::const_iterator itr = mResources.find(key);
            return (itr != mResources.end()) ? *(itr->second) : mDefault;
        }
    

    itr->second is a smart pointer, so if you want to get the pointer object, you simply need to dereference the smart pointer: *(itr->second).

    As for returning a reference to mDefault, this is indicated by the function’s return type const T &, so you don’t need anything more.

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

Sidebar

Related Questions

I have a generic function for XMLHttpRequests. as follows: function XMLRequest(address, data){ this.html =
My code is as follows: $.getJSON(http://xx.xx.x.x/directory/index.php?c=json&m=get_listing&jsoncallback=?, { action:'listings' }, function(data) { // code });
I'm having a set of row data as follows List<String> l_lstRowData = new List<string>
EDIT: Apparently, the problem is in the read function: I checked the data in
I use fileuploader Jquery, I tried to form defined as follows: <Form enctype="multipart/form-data" action="<%:Url.Action("Edit","Ticket")%>"
I am looking for a way to edit data and have values dynamically calculated
I have two view controllers in a tabbar which can both edit data. Therefore,
I've been experimenting with using MS Excel 2007 to edit tabular data stored in
To allow users and site admins to view/add/edit/delete data in my application I decided
I am using the flex datagrid to allow the user to edit some data.

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.