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

The Archive Base Latest Questions

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

I have removed all the unwanted segments. I am trying to pass pointers to

  • 0

I have removed all the unwanted segments. I am trying to pass pointers to an overloaded operator and use templates too. But this is still not working.

#include<iostream.h>
#include<conio.h>

class Test{
      private:
             int a;
      public:
             Test (){}
             Test(int k){
                a=k;
             }
             Test* operator +(Test *p){
                  Test *temp=new Test(this->a+p->geta());
                  return temp;
             }
             int geta(){
                  return a;
             }
};

template<class T>  
   T* sum(T* a,T* b){
   return a+b;
}

int main(){
    Test *t1,*t2;
    t1=new Test(5);
    t2=new Test(7);
    Test *z=sum(t1,t2);
    cout<<z->geta();
    getch();
}
  • 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-20T08:24:38+00:00Added an answer on May 20, 2026 at 8:24 am

    Firstly, t1 is a pointer, and you are calling the add method incorrectly – should be t1->add(t2). Secondly, the sum() methods takes arguments which are not pointers, i.e. the template parameter is deduced as Test rather than Test*, hence you need to change the signature to something like:

    template <typename T>
    T* sum(T* a, T* b)
    {
      return a->add(b); // or some variant...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a window with 3 radiobuttons like this(removed all non interesting props): <Control
I have this method which will remove all rows from a table but I
I have removed all Input Managers that were added, but it's still happening. Here
I have two entities // All details has been removed @Entity @Table(name = "A_TABLE_NAME")
I'm trying to remove all of the leaves. I know that leaves have no
I have this HTML string which often has a lot of whitespaces Example: <p>All
Note: I have removed all required error checking in the following snippet. ... void
Update: Please see below; I have removed all abstraction and created a plain PHP
i have removed all unnecessary variables andtried to focus directly on the problem at
I have a simplified ajay script, from which I have removed all nonrelevant code.

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.