Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > bitset

Reply
Thread Tools

bitset

 
 
Anders
Guest
Posts: n/a
 
      07-17-2003
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;

...


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      07-17-2003

"Anders" <anders> wrote in message
news:3f170412$0$32530$ 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


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-17-2003
"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


 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      07-17-2003

"Anders" <anders> wrote in message news:3f170412$0$32530$ 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bitset<32> and bitset<64> efficiency Ninds C++ 14 12-03-2012 11:02 PM
Is 'java.util.BitSet' available at JDK1.3? Joshua Java 4 05-06-2005 11:54 AM
Performance of java.util.BitSet Timo Nentwig Java 4 12-11-2003 12:43 AM
Re: bitset to UCHAR Victor Bazarov C++ 1 07-08-2003 09:11 PM
std::bitset construction with std::string question Dill Hole C++ 2 07-04-2003 11:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57