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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:14:24+00:00 2026-05-27T20:14:24+00:00

According to C++03 Standard (23.1/3) only copy-constructible class objects can be stored in STL

  • 0

According to C++03 Standard (23.1/3) only copy-constructible class objects can be stored in STL containers. Copy-constructible is described in 20.1.3 and requires that “&” yields address of the object.

Now suppose I have this class:

class Class {
public:
   Class* operator&()
   {
       //do some logging
       return this;
   }
   const Class* operator&() const
   {
       //do some logging
       return this;
   }
   //whatever else - assume it doesn't violate requierements
};

Can this class objects be legally stored in STL containers?

  • 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-27T20:14:25+00:00Added an answer on May 27, 2026 at 8:14 pm

    Yes. In C++03, the CopyConstructible requirements for &, given values t of type T and u of type const T, are:

    • &t has type T*, and gives the address of t, and
    • &u has type const T*, and gives the address of u.

    Your overloaded operators have this behaviour; so, assuming the class meets the other CopyConstructible and Assignable requirements, values of this type can be stored in any C++03 container.

    C++11 relaxes these requirements, requiring that types be movable or copyable only in containers or operations that specifically have such requirements, and removing the rather odd specification of what & must do; so your class is still fine, again assuming it meets all the other requirements for the particular container and set of operations you use.

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

Sidebar

Related Questions

According to C++ standard (3.7.3.2/4) using (not only dereferencing, but also copying, casting, whatever
Do class destructors have names in the pedantic sense according to the Standard? Recall
According to C++ Standard paragraph 3.7.3/1 objects should be dynamically created with new expression
According to Androids documentation I get the impression, that Android only supports ISO 8601
getpwnam_r() is reentrant according a number of manpages. However, the standard only state The
According to the standard, a conversion function has a function-id operator conversion-type-id , which
According to this discussion , the iphone agreement says that it doesn't allow loading
According to what I have found so far, I can use the following code:
I have a Java client that consumes SharePoint 2010 standard web services (sitedata.asmx, permissions.asmx,
According to the standard (§5.2.11) a const_cast casts away cv-qualifiers (const or volatile). Here's

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.