Home > Back-end > C why template class can reference character array? In the face of the array in C direct reference i
C why template class can reference character array? In the face of the array in C direct reference i
Time:11-09
//write a template class yesterday, found that is defined as the character array after it is lawful to reference, feel very strange, then write a general reference found that it was illegal, code is simplified as follows:
TemplateThe class test { Public: The test (const T & amp; A) { } };
The class test1 { Public: Test1 (const char * & amp; A) {} };
Int main ()
{
TestTest1 * t1=new test1 (" fun ");//illegal return 0;
}
//don't understand why, just contact template class, meet you
CodePudding user response:
I think I may be because the const didn't modify & amp; The reason, if you define an alias: Typedef char * PChar; And then the test1 (const PChar & amp; A); I don't know this line not line?