Home > Back-end >  C template. The template structure
C template. The template structure

Time:09-25

Template
Void printBitset (STD: : bitset Const& Bs)
{
STD: : cout Allocator (a);
}

Inside this bs. The template to_string & lt; Char, char_traits & lt; Char> Allocator () this grammar don't understand, this to_string & lt; Char, char_traits & lt; Char> Allocator () is a function call, then in front of the bs. The template and expressed what do you mean

CodePudding user response:

The building Lord, found in vs2013 debugging, the bs. The above template to_string & lt; Char, char_traits & lt; Char> Allocator (a); Code eventually invoke the code below:
 templateThe class _Tr, 
The class _Alloc & gt;
Basic_string & lt; _Elem _Tr, _Alloc & gt;
To_string (_Elem _E0=(_Elem) '0',
_Elem _E1=const (_Elem) '1')
{//convert bitset to string
Basic_string & lt; _Elem _Tr, _Alloc & gt; _Str;
Typename basic_string & lt; _Elem _Tr, _Alloc & gt; : : size_type _Pos;
_Str. Reserve (_Bits);

For (_Pos=_Bits; 0 <_Pos; )
If (test (-- _Pos))
_Str +=_E1;
The else
_Str +=_E0;
Return (_Str);
}


And it is the code in the bitset class template to_string code, so the speculation, personally think: in front of the bs. The template is tells the compiler to invoke bitset class template to_string function in the output,

CodePudding user response:

reference 1st floor SGHCPT response:
the building Lord, found in vs2013 debugging, the bs. The above template to_string & lt; Char, char_traits & lt; Char> Allocator (a); Code eventually invoke the code below:
 templateThe class _Tr, 
The class _Alloc & gt;
Basic_string & lt; _Elem _Tr, _Alloc & gt;
To_string (_Elem _E0=(_Elem) '0',
_Elem _E1=const (_Elem) '1')
{//convert bitset to string
Basic_string & lt; _Elem _Tr, _Alloc & gt; _Str;
Typename basic_string & lt; _Elem _Tr, _Alloc & gt; : : size_type _Pos;
_Str. Reserve (_Bits);

For (_Pos=_Bits; 0 <_Pos; )
If (test (-- _Pos))
_Str +=_E1;
The else
_Str +=_E0;
Return (_Str);
}


And it is the code in the bitset class template to_string code, so the speculation, personally think: in front of the bs. The template is tells the compiler to invoke bitset class template to_string function in the output,

, yes, just this syntax, and have never met, feel the back of the template and tostring should contain brackets, or difficult to understand

CodePudding user response:

Inside this bs. The template to_string & lt; Char, char_traits & lt; Char> Allocator () look not to understand the syntax
================
Bs is a object
To_string this function called
This function is a template function

Is an example of the book,

CodePudding user response:

Ha ha, bs. The template is a prompt and suggest that call is a template class STD: : bitset A member function to_string

CodePudding user response:

If there is no template, the compiler can't learned that followed "& lt;" The initiation of is a representative of the template argument list, rather than a "less than" signs,
  • Related