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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:05:23+00:00 2026-06-14T12:05:23+00:00

I’m wondering about one thing. I’ve got class which has 1 overloaded member function:

  • 0

I’m wondering about one thing. I’ve got class which has 1 overloaded member function:

class A{
    public:
    class const_iterator{};
    class iterator : public const_iterator{};
    iterator find(const K &key);
    const_iterator find(const K &key) const;
};

Ad. iterator is inheriting from const_iterator, but it isn’t adding anything.

What I want to do is, inside normal find call const find. Something like this:

typename A::iterator A::find(const K &key){
     const_iterator it(find(key));
     return (*(iterator*)&it);
}

I don’t need different implementation of non-const find ATM. Is it possible to do something like this? Because now I’m getting into infinite loop, adding “A::” before find isn’t changing anything.

  • 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-14T12:05:24+00:00Added an answer on June 14, 2026 at 12:05 pm

    In general, there’s no clean solution for this, unfortunately.

    You can call the overloaded find by simply casting this to A const* – but the result will be of the wrong type (const_iterator rather than iterator) and there may not be a conversion between these in the general case (your (*(iterator*)&it) won’t work in your case).

    But of course, in your special case, since you defined the two classes, you can define such a conversion by adding an appropriate constructor to iterator:

    class iterator : public const_iterator {
        iterator(const_iterator const& other) { 
            // Construct …
        }
    };
    

    Then you can re-write your non-const find implementation as follows:

    A::iterator A::find(const int &key){
        const_iterator it(const_cast<A const*>(this)->find(key));
        return static_cast<iterator>(it);
    }
    

    Incidentally, note the absence of typename in the return type. Since A::iterator isn’t a dependent name, you don’t need (and, at least in C++03, are not allowed to) use typename here.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.