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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:19:04+00:00 2026-05-24T08:19:04+00:00

I have set of classes. Each class is inherited from another class. The relationship

  • 0

I have set of classes. Each class is inherited from another class. The relationship is as follows. (I am just posting how one class inherited from another class, just to get idea for all of you)

class LineNumberList : public MyVector <LineNumber > //top class
class MyVector : public std::vector <Type>
class LineNumber : public ElementNumber 

class ElementNumber {                 //this is the base class
        protected:
    int number;
        public:
    ElementNumber(int p){number=p;}
         // some more codes // 
}

Now, I want to implement a function which can be used to find elements inside my topclass i.e. LineNumberList. I tried with standard find function, but it doesn’t work. Can anyone help me to implement similar find function for my case, it is highly appreciated.

  • 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-24T08:19:05+00:00Added an answer on May 24, 2026 at 8:19 am

    “I tried with standard find function, but it doesn’t work.” Works for me:

    #include <vector>
    #include <iostream>
    #include <algorithm>
    
    class ElementNumber {
      protected:
        int number;
      public:
        ElementNumber(int p) :number(p) {}
        bool operator==(const ElementNumber&e) { return number == e.number; }
    };
    class LineNumber : public ElementNumber {
      public:
        LineNumber(int p) : ElementNumber(p) {}
    };
    template <class Type>
    class MyVector : public std::vector<Type> {
    };
    class LineNumberList : public MyVector<LineNumber> {
    };
    
    // EDIT: add local implementation of std::find
    template<class InputIterator, class T>
    InputIterator myfind ( InputIterator first, InputIterator last, const T& value )
    {
      http://www.cplusplus.com/reference/algorithm/find/
      for ( ;first!=last; first++) if ( *first==value ) break;
      return first;
    }
    
    int main() {
      LineNumberList ll;
      LineNumber l(7);
      ll.push_back(l);
      std::cout << std::boolalpha << !(std::find(ll.begin(), ll.end(), l) == ll.end()) << "\n";
      std::cout << std::boolalpha << !(::myfind(ll.begin(), ll.end(), l) == ll.end()) << "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes, WebServiceRequest and OrderRequest. Each class has properties. OrderRequest inherits from
I have set of classes which inherit from a single super class: Super |
I have a set of XSDs from which I generate data access classes, stored
I want to know if one class is inheriting from another, is it better
We have a set of about two dozen classes that inherit from a base
I have a number of LINQ classes that inherit from the same base class.
I have a class called ItemBase from which a number of classes inherit. In
I have a fairly complex set of C++ classes that are re-written from Java.
If have a set of classes that all implement an interface. interface IMyinterface<T> {
Present Scenario : I have a set of classes that all take a common

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.