#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
using namespace std;
template <class T>
T Summation(T a, T b, T c) {
return (a+b+c);
}
int main() {
char e = '5', f = '6', g = '7', h;
int a = 5, b = 6, c = 7, d;
h=Summation<char>(e,f,g);
cout << h << endl;
d=Summation<char>(a,b,c);
cout << d << endl;
}
我必須使用求和一個模板,我需要打印出18相同的類型參數的。所以程序應該返回18作爲char類型,那麼下一行應該返回18作爲int類型。我怎樣才能得到三個char數字的總和?
通過3個參數? –
是的,對不起,這是一個錯誤,但我糾正它 – user1082764
如果字中,h == 18',然後'COUT << h'可能只打印空白。 – aschepler