C++: combine const with template arguments

后端 未结 6 1496
清酒与你
清酒与你 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:43

    Substituting T with char* gives a const pointer to char, while c is declared as a pointer to const char.

    A solution would be to take pointers and integral types by value and class types by const reference. If you can, use Boost Call Traits which solves these kinds of problems for you.

提交回复
热议问题