![]() |
bitset
Hello.
Can anyone tell me why you have to explicitly write the template parameters in the .to_string() method? e.g: bitset<8> bit(string("11")); cout << bit.to_string<char, char_traits<char>, allocator<char> >() << endl; ... |
Re: bitset
"Anders" <anders> wrote in message news:3f170412$0$32530$edfadb0f@dread16.news.tele.d k... > Hello. > > Can anyone tell me why you have to explicitly write the template parameters > in the .to_string() method? e.g: > > bitset<8> bit(string("11")); > cout << bit.to_string<char, char_traits<char>, allocator<char> >() << endl; > Noramlly which version of a template function is called is worked out based on the types of the parameters of that function. Since to_string does not have any parameters you have to tell the compiler explicitly which kind of string you want returned. john |
Re: bitset
"Anders" <anders> wrote...
> Can anyone tell me why you have to explicitly write the template parameters > in the .to_string() method? e.g: > > bitset<8> bit(string("11")); > cout << bit.to_string<char, char_traits<char>, allocator<char> >() << endl; Because 'to_string' is a template member. You only need to specify the first one, by the way: bit.to_string<char>() However, *I* don't have to do that to output the actual bitset: #include <bitset> #include <iostream> #include <string> using namespace std; int main() { bitset<8> bit(string("11")); cout << bit << endl; } works fine for me. It prints 00000011 Victor |
Re: bitset
"Anders" <anders> wrote in message news:3f170412$0$32530$edfadb0f@dread16.news.tele.d k... > Hello. > > Can anyone tell me why you have to explicitly write the template parameters > in the .to_string() method? e.g: > > bitset<8> bit(string("11")); > cout << bit.to_string<char, char_traits<char>, allocator<char> >() << endl; Functions are not overloaded by return value. It doesn't know what kind of string you wanted to convert it to. |
| All times are GMT. The time now is 05:13 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.