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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:40:51+00:00 2026-05-27T10:40:51+00:00

I had to build a const_iterator wrapper to exchange generic programming with dynamic binding

  • 0

I had to build a const_iterator wrapper to exchange generic programming with dynamic binding (never mind this). However std::set<Base*>::const_iterator::operator*() gives me something I didn’t expect, because I have trouble returning it in a Derived* const& where Derived publicly inherits from Base.

template <typename T, typename Container> class StdConstIterator : public ConstIteratable<T> {
  private:
    typename Container::const_iterator it;
  public:
    T const& operator*() const {
      return *it; // g++ says: warning: returning reference to temporary
    }
};

// invokation
StdConstIterator<Derived*,std::set<Base*> > si;

While I see that it might be reasonable for pointers to copy them instead of returning a reference, I fail to find a specialisation in my STL’s implementation. Could you shed some light on the issue, please?

Note: You might know the routine; Unfortunately no C++11 support, so I cannot decltype myself out of this. But this is more of a “what the heck is going on here?” sort of question, anyway.

  • 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-27T10:40:52+00:00Added an answer on May 27, 2026 at 10:40 am

    Most likely is that there’s some conversion going on. Instead of T you should use the actual iterator’s value type, typename Container::const_iterator::value_type. If that type isn’t the same as T, then the conversion creates a temporary, to which you attempt to return a reference.

    On the other hand, if you do want the conversion, then return by value, T operator*() const.

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

Sidebar

Related Questions

I had never tried Continuum as a build server until recently when a project
So just this week I had the opportunity to re-build my development machine and
I've never used an automated build system - to be honest, I've never had
I have spent way to much time on this I had to build the
I was wondering if anyone knew whether Visual Studio .NET had a parallel build
I had been asked to build crystal reports for an application, i used the
Has anybody had any success getting Team Build to show xUnit.net test results and
had to return to a old app I had build in Classic ASP and
I recently had my mind expanded by a new concept: Web Services for Remote
So I was writing some code, and I had something like this: class Box

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.