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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:32:45+00:00 2026-06-13T08:32:45+00:00

So I have the following method: template <class DT> //needs testing DT& LinkedSortedArrays<DT>::find (const

  • 0

So I have the following method:

template <class DT> //needs testing
DT& LinkedSortedArrays<DT>::find (const DT& key)
{
    list<SortedArray<DT>>::iterator it = SAList.begin();
    for( ; it != SAList.end(); ++it){
        try{
            if (it == SAList.begin() && key < (*it)[0]) throw Exception();
            return (*it).find(const_cast<DT&> (key));
        } catch (ArrayException e) {

        }
    }
    throw Exception();
}

I have previously defined the classes Exception and ArrayException. (*it).find(const_cast<DT&> (key)) will throw a ArrayException everytime that key is not found in the specific Array class being searched at the moment. SAList is a STL List. The code compiles just fine. However I haven’t tried it in my program. Why? I need somebody to confirm or correct me on the following assumptions I have done:

  1. Whenever if (it == SAList.begin() && key < (*it)[0]) throw Exception(); throws an exception, it means it will throw it outside the for loop and even outside the method, right?
  2. I am almost sure that the last line throw Exception(); will throw the Exception outside the method.
  3. The way the for loop is arranged, it won’t skip the first element of SAList, right? I mean, I have seen this specific code all over the internet that serves to iterate through all elements of the list as if it was standard or flawless, but… that ++it is twisting my brain. Help?
  4. I was receiving an error of can't convert const int to int& (since the find() in (*it).find(const_cast<DT&> (key)) is not the one belonging to LinkedSortedArrays but rather a different one that requires a DT& variable and LinkedSortedArrays‘s find() has parameters of type const DT&) and I found that a possible solution might be writing it as const_cast<DT&> (key). I need a second opinion on this.

Lastly, I understand if this is not a specific question and therefore I get downvotes and/or the question gets closed. I simply don’t really know where else to ask.
If it is the case that I am asking in the wrong place. My apologies.

  • 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-13T08:32:46+00:00Added an answer on June 13, 2026 at 8:32 am
    1. Yes, it will go up the stack until it finds the appropriate catch handler. If it finds no such handler, the program will terminate.

    2. Yes it will.

    3. No, it will not, since end should return an iterator to one past the end, not the last element. Unless that container is badly designed as well, but you’ll have to consult the documentation to be sure.

    4. That’s a bad design, find should take its parameter by const reference. Since you can’t, you’ll have to make a copy unless you want to risk undefined behaviour:

      DT nonconstkey = key;
      return it->find(nonconstkey);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following template method declared in my interface: class IObjectFactory { public:
I have the following method in my UIButton class: - (id)initWithCoder:(NSCoder *)aDecoder{ self =
I have the following method which is called when the value Edit Class... is
I have the following setup: A templated class SpecialModel: template<typename A, typename B> class
I have a template class, and would like to write a member method that's
I have a class similar to the following: class SomeClass { public: template<typename... Args>
I have the following view model: Public Class MyViewModel Public Property SelectedIDs As List(Of
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have following method which I am using to load ActiveX control dynamically, Dim
I have the following method, which takes in the name of a file as

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.