新手:使用template关键字
C++编程思想里的一个例子
#include <bitset>
#include <cstddef>
#include <iostream>
#include <string>
using namespace std;
template<class charT, size_t N>
basic_string<charT> bitsetToString(const bitset<N>& bs) {
return bs. template to_string<charT, char_traits<charT>,
allocator<charT> >();
}
int main() {
bitset<10> bs;
bs.set(2);
bs.set(5);
cout << bs << endl;
string s = bitsetToString<char>(bs);
cout << s << endl;
return 0;
}
编译提示错误:error C2783: 'class std::basic_string<charT,struct std::char_traits<charT>,class std::allocator<charT> > __cdecl bitsetToString(const class std::bitset<charT> &)' : could not deduce template argument for 'N'
是什么意思?