The following example works when I manually replace Twirh char *, but why it doesn't work, as it is:
T
char *
template <typename T> class A{ public: A(const T _t) { } }; int main(){ const char * c = "asdf"; A<char *> a(c); }
When compiling with gcc, I get this error:
test.cpp: In function 'int main()': test.cpp:10: error: invalid conversion from 'const char*' to 'char*' test.cpp:10: error: initializing argument 1 of 'A<T>::A(T) [with T = char*]'
Try converting to const T &. In addition, in these cases, you should allow the compiler to automatically output the template argument and not specify it.
Substitution Twith char*gives a pointer constto char, and is cdeclared as a pointer to const char.
char*
const
c
const char
, . , Boost Call Traits, .
, const (char *) ( T char *), , , const char * (const char) *, .. , .
const (char *)
const char *
(const char) *
, , , T = char* , , (c), char* ( : a const char*) .
T = char*
const char*
:
const_cast
A<const char *> a(c);
- # 3. , , "", : , A, . , , , , T const.
c, .
, , const. const , T_t, const ... , .
A(const char* _t), A( (const char) *t). const char. char* , A( const (char *t)) const char.
A(const char* _t)
A( (const char) *t)
A( const (char *t))
In other words, I think that you have the same problem that is mentioned in the article “Summer Madness of the Summer Sun” , except for the template parameters instead of typedefs.
Source: https://habr.com/ru/post/1745186/More articles:How can I do the following drawing in opengl? - openglCURL alternative due to long wait - phpOpenGl: stencil buffer problem (Wall + Window)? - openglСжатие Zlib в boost:: iostreams несовместимо с zlib.NET - c#иерархические данные из таблицы саморекламы в виде дерева - sqlJQuery Count animation? - javascriptAquamaki and IDLWAVE - emacsQuestion about XML deserialization in .net - c #how to solve "Digg" problem in MongoDB - javaHow do you access @ font-face in the DOM (via Javascript)? - javascriptAll Articles