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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:06:32+00:00 2026-06-14T04:06:32+00:00

I have template method and i would like the template method use a specific

  • 0

I have template method and i would like the template method use a specific method from a class to do the operation. Is it possible ?

template<typename T>
int minus(T t1,T t2){
return t1-t2;
}

And in my apple object class i have a method called getPrice()
How can i combine both.

Is this correct ?

template<typename T>
int minus(T t1,T t2){
return t1.getPrice()-t2.getPrice();
}
  • 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-14T04:06:33+00:00Added an answer on June 14, 2026 at 4:06 am

    For this you probably want an ordinary function for your type:

    template <class T>
    int minus(T t1, T t2) {
        return t1 - t2;
    }
    
    int minus(const apple& t1, const apple& t2) {
        return t1.getPrice() - t2.getPrice();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a template method as follows:- template<typename T, int length> void ProcessArray(T array[length])
I have a template class method like that: template<class T> static tmpClass<T>* MakeInstance(T value)
I have the following template method declared in my interface: class IObjectFactory { public:
I'm trying to return a left child as a pointer I have template <typename
I have a class in C# with a template and static method similar to
I am trying to understand a template class in C++. First, I would like
I often get into situation when I'd like to use template method pattern, but
I have a template class which looks like the following: template <template <class TypeT>
I want to make a class that will have a single get template method
Suppose you have a class like template<class T> struct A { void foo() {

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.