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

  • Home
  • SEARCH
  • 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 8146575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:03:17+00:00 2026-06-06T14:03:17+00:00

I will use std::map<int, A> A is a class and I have to prevent

  • 0

I will use std::map<int, A>

A is a class and I have to prevent shallow copy,
but there are many classes like A, so making a deep copy construct and operator is tiresome.
Since it seems that I don’t have to use copy constructor and copy assignment operator,
I decide not to use them.

To prevent some mistakes, I made UnCopyable class, which has private copy constuctor and copy assignment operator, and A inherited it.

However, there is one problem. std::map use a copy constructor.

I don’t want to save A‘s pointer in the map.

What’s the better solution?

  • 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-06T14:03:21+00:00Added an answer on June 6, 2026 at 2:03 pm

    You could use a smart pointer like std::shared_ptr or write a proxy class.

    E.g.:

    class Foo {
    public:
        std::string name() const;
    };
    
    typedef std::shared_ptr<Foo> SharedFoo;
    

    or

    class SharedFoo {
    public:
        std::string name() const { return instance->name(); }
    private:
        std::shared_ptr<Foo> instance;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I use following syntax: std::map<int,std::list<int>> mAllData; Where Key Value(int) will be ID of
Assume I have a class foo, and wish to use a std::map to store
I will use (again) the following class hierarchy: Event and all the following classes
I would like to copy the content of one std::map into another. Can I
I have a std::map that I use to map values (field ID's) to a
I have one base class which holds a map for function pointers like this
I have a std::map, and I would like to add a valid key to
I will use the following javascript to display a Google Map Window in a
My script below will use two external tables to fill two separate tables, but
I'm working on a website that will use features of social networking (like facebook

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.