我想要编译:模板错误的代码块,C++,代码块,错误
#include<iostream>
#include"gettype.*"
using namespace std;
int main() {
int i;
cout << getType(i) << endl;
unsigned int ui;
cout << getType(ui) << endl;
char c;
cout << getType(c) << endl;
double d;
cout << getType(d) << endl;
bool b;
cout << getType(b) << endl;
float f;
cout << getType(f) << endl;
}
有了这个为模板:
#ifndef GETTYPE_T
#define GETTYPE_T
template <typename T>
std::string getType(T t) { return "unbekannter Typ";}
template<typename T> std::string getType(int t) { return "int";}
template<typename T> std::string getType(unsigned int t) { return "unsigned int";}
template<typename T> std::string getType(double t) { return "double";}
template<typename T> std::string getType(char t) { return "char";}
template<typename T> std::string getType(bool t) { return "bool";}
#endif
我收到此错误,从控制台的代码块:
||=== Build: Debug in gettype.t (compiler: GNU GCC Compiler) ===|
gettype.t.c|6|error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token|
gettype.t.c|9|error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token|
gettype.t.c|10|error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token|
gettype.t.c|11|error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token|
gettype.t.c|12|error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token|
gettype.t.c|13|error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token|
||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
我不知道这里有什么错... :-(提前为您的时间:-) 欢呼声。
'的#include “gettype。*”'??? –
仅供参考,问题标题不是标签,而是标题。 – HolyBlackCat
#包括“gettype。*”是一个错误...它不适用于扩展名.t – James