运算符重载程序以添加数字和字符串

时间:2019-05-24 18:10:34

标签: c++

我想制作一个可以添加字符串(串联)和数字(int或float)的程序。程序有效,但最后它也输出Trap,我没有写过,所以它表示什么 很抱歉给您带来不便。

#include <iostream>
#include <cmath>
#include <cstring>
#include <typeinfo>
  using namespace std;

  template <class test>
  class Test {
    public:
   test operator+(){
     test Ss= typeid("hi").name();
      test a,b,c;
      if(a == Ss){
      a.concat(b);
      }else{
         test c = a+b;
    }
 }
   test ask_f(test a, test b){
     test c=a+b;
        cout<<c<<end;
  };
      int main(){
       Test <int> t1;
       t1.ask_f(5,6);
  }

0 个答案:

没有答案