我尝试在以下代码中使用模板,但我在 main 函数的第一行遇到了问题!
{
#include <iostream>
using namespace std;
template <class T>
struct node
{
T inf;
node<T> * next;
};
template <class S>
class String
{
private :
int Slength;
node<S> * SS;
public :
void get_String()
{
SS = new node<S>;
SS -> next = NULL;
node<S> * now = SS;
char input;
while(input = getchar())
{
if((input =='\n') || (input == ' ') || (input == '\t'))
break;
now -> inf = input;
now -> next = new node<S>;
now = now -> next;
now -> next = NULL;
++Slength;
}
}
void show()
{
node<S> * now = SS;
while(now -> next != NULL)
{
cout << now -> inf ;
now = now -> next;
}
cout << endl;
}
};
int main()
{
String a;
a.get_String();
a.show();
cout << char(0) << " " << int(' ') << " " <<endl;
system("pause");
return 0;
}
我通过添加解决了问题
<char>
在那之后!有没有其他好的和有效的方法。你知道任何可靠且可读的模板参考吗?