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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:37:04+00:00 2026-05-23T08:37:04+00:00

I tried to create a container for posible metadata that can be attached to

  • 0

I tried to create a container for posible metadata that can be attached to my objects. I can guarantee that there will be at most one object af each kind attached to my class but there is no limit for object of different type to attach. for example I can’t attach two instances of wordInfo to an object but instances of wordInfo and phraseInfo classes can be attached to an object at a same time. here is what I did so far to get it done.

class object
{
    std::map <std::type_info, object*> mMetaData;
    public:
    inline void attachMetaData(object* pData)
    {
        mMetaData[typeid(*pData)] = pData;
    }
    template <class T> inline std::enableif<std::is_base_of<object,T>::value, T*>::type getMetaData()
    {
        if (mMetaData.find(typeid(T)) == mMetaData.end())
            return NULL;
        else
            return mMetaData[typeid(T)];
    }
    template <class T> inline std::enableif<std::is_base_of<object,T>::value, void>::type detachMetaData()
    {
        mMetaData.erase(typeid(T));
    }
}

the code above had a compile error : less operator was not defined for std::type_info so I defined some less class specifically for std::type_info and pass it as the third template parameter of map class like this:

struct typeinfoless
{
    bool operator()(std::type_info& left, std::type_info& right)
    {
        return left.hash() < right.hash();
    }
}
std::map <std::type_info, object*, typeinfoless> mMetaData;

but then I encountered another error which I don’t know how to resolve, std::type_info has private constructor and even private copy constructor, so I can’t even derive some class from it. any idea how can I fix this problem? or any other possible way to create my object class?

  • 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-23T08:37:04+00:00Added an answer on May 23, 2026 at 8:37 am

    Create a wrapper class for std::type_info, similar to the following:

    class TypeWrapper
    {
        private const std::type_info &mInfo;
        public TypeWrapper(const std::type_info &info) : mInfo(info)
        {
        }
        // Functions required by a key into a std::map.
    };
    

    Use TypeWrapper as your key into your map.

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

Sidebar

Related Questions

I tried to create one array of strings in C. Here is the code:
I'm trying to create an element that contains a form so it can be
I am trying to create a WPF application that will be a central point
I tried to create this by following the video at http://www.asp.net/learn/videos/video-7026.aspx where Joe Stagner
I tried to create a Style for DataGridTextColumn with the following code <Style TargetType={x:Type
I tried to create a file using Oracle UTL_FILE.FOPEN command but i get this
I tried to create a new Swing GUI desktop application template using NetBean 7.0
I have tried to create a hello world Web Service using visual studio 2008,
Have anybody ever tried to create thumbnails/previews of MS Office files? I do not
when I tried to create a shared library file using the cl command in

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.