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

  • Home
  • SEARCH
  • 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 1108643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:07:00+00:00 2026-05-17T02:07:00+00:00

hello i am building a template in c++ ,and i need to overwrite the

  • 0

hello i am building a template in c++ ,and i need to overwrite the operator “<” inside the template for being able to compare between items inside my data structure.
could anyone please tell me how to overwrite it … should i send a pointer to a function inside the constructor of the template?
I got two templates, the first one is Node template which includes a pointer to the data that i am managing.
and the second is a Heap template which has an vector of nodes*.
in my implementation i should be able to compare between nodes*.

  • 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-17T02:07:01+00:00Added an answer on May 17, 2026 at 2:07 am

    Will this do? I have purposely provided ‘operator <‘ in the namespace scope so that it is more generic, though it is shown in comments how to do so.

    template<class T> struct A;
    
    template<class T, class U>     // Remove U and modify accordingly, if f and s
                                   // have to be of the same type.
    bool operator < (A<T> const &f, A<U> const &s){
       // have the logic here
       return true;
    }
    
    template<class T> struct A{
       // template<class U>                // This is how you define inside a class.
       // bool operator < (A<U> const &s){
       //    have logic here
       //    return true;
       // }
    };
    
    int main(){
       A<int> a;
       A<double> d;
    
       bool b = a < d;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i'm building a wpf app with data grids, the pattern is model view
Hello I'm building a Spring MVC web application that runs on Tomcat 6.0.20 and
Hello I'm building a web application with spring ibatis and mysql. I'm going to
(source: kominetz.com ) Hello. I'm diving into iOS development and am building my own
Possible Duplicate: NSNumberFormatter and ‘th’ ‘st’ ‘nd’ ‘rd’ (ordinal) number endings Hello, I'm building
I'm building a very interactive site with lots of ajax type functions. I'm starting
I compiled a simple hello world C module for Python and it works correctly
hello i have a desktop application that communicate with a wcf service that i
Hello I am putting together a tool chain on my windows Box for Cross
I want to develop my next web project in C++ as FastCGI but I

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.