C++: combine const with template arguments

后端 未结 6 1506
清酒与你
清酒与你 2020-12-18 11:46

The following example is working when I manualy replace T wirh char *, but why is not working as it is:

template          


        
6条回答
  •  悲哀的现实
    2020-12-18 12:28

    If you make your constructor A(const char* _t), you're getting effectively A( (const char) *t). That is, a pointer to const char. But when you specify char* as the template parameter, you're getting effectively A( const (char *t)), or a const pointer to char.

    In other words, I think you have the same problem discussed in the article A Midsummer Night's Madness, except with template parameters instead of typedefs.

提交回复
热议问题