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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:57:08+00:00 2026-06-07T02:57:08+00:00

I am building an STL list. I made a decorator class ( MyList )

  • 0

I am building an STL list. I made a decorator class (MyList) that is a list of a special class (ProtectMe). I want all of the items of the list to be const. So here’s what I made:

#include <list>

using namespace std;

class ProtectMe{
private:
    int data_;
public:
    ProtectMe(int data):data_(data){
    }

    int data() const{return data_;}
};

class MyList{
private:
    //A list of constant pointers to constant ProtectMes.
    list<const ProtectMe* const> guts_;
public:
    void add(const ProtectMe& data){
        guts_.push_front(&data);
    }
};

I get the following compile error:

error: ‘const _Tp* __gnu_cxx::new_allocator::address(const _Tp&) const [with _Tp = const ProtectMe* const]’ cannot be overloaded

I’m still scratching my head trying to decode where I went wrong. Why doesn’t this code compile? What should I change?

  • 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-07T02:57:09+00:00Added an answer on June 7, 2026 at 2:57 am

    The value_type of standard containers must be CopyInsertable (or MoveInsertable) in order for the push_front to work. The value type of list<const ProtectMe* const> is constant, so it’s not CopyInsertable.

    † CopyInsertable means that

    allocator_traits<A>::construct(m, p, v);
    

    is well defined where p is a pointer to value_type, which by default calls placement new on p and thus requires it to be a non-const pointer.

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

Sidebar

Related Questions

Building a quick view that will display a list of all days but only
Building a simple app here; the methods in question: static coin class public static
building a site using PHP and MySQL that needs to store a lot of
Building a website that has English & Japanese speaking users, with the Japanese users
Building a search with some custom objects and three scopes: All , Active ,
Building an iPhone OS application that will allow users to anonymously post information to
I have a problem with stl priority queue.I want to have the priority queue
Building a commercial product may use various open source libraries that have use of
Building a site super quick and having it work on all my Mac browsers,
Building an NSCharacter set to restrict a UITextField for entering user names. I want

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.