template confusion
-
Learning programmer need some help. I understand c++ Classes and I used to think I understood namespaces. But while trying to learn templates I'm getting kinda confused what is going on with this template example. template const CharT* std::basic_string< CharT, Traits, Alloc >::c_str() const [inline] //and later the definition of the member function c_str() const _CharT* c_str() const { return _M_data(); } (a) Do you call the first line the template declaration? (b) Do you call the second line the template implementation or definition? (c) It appears to be a scope resolution :: to the member function c_str() but what is the [inline] bracket syntax? (d)Also I assume the < CharT, Traits, Alloc > are defined in the header (elsewhere) with some value (overloaded or not)? Just anywhere you can illuminate what I'm missing on the concept.
-
Learning programmer need some help. I understand c++ Classes and I used to think I understood namespaces. But while trying to learn templates I'm getting kinda confused what is going on with this template example. template const CharT* std::basic_string< CharT, Traits, Alloc >::c_str() const [inline] //and later the definition of the member function c_str() const _CharT* c_str() const { return _M_data(); } (a) Do you call the first line the template declaration? (b) Do you call the second line the template implementation or definition? (c) It appears to be a scope resolution :: to the member function c_str() but what is the [inline] bracket syntax? (d)Also I assume the < CharT, Traits, Alloc > are defined in the header (elsewhere) with some value (overloaded or not)? Just anywhere you can illuminate what I'm missing on the concept.
I still haven't understood the [INLINE] square brackets thing (yet) but I've begun to understand the templates concept amongst all the syntax MUCH better when I found this Article here on Code Project. An Idiots Guide to C++ Templates-Part-1 So I guess I'm an idiot since that page helped me more than any I've read previous. A happy idiot now.
-
I still haven't understood the [INLINE] square brackets thing (yet) but I've begun to understand the templates concept amongst all the syntax MUCH better when I found this Article here on Code Project. An Idiots Guide to C++ Templates-Part-1 So I guess I'm an idiot since that page helped me more than any I've read previous. A happy idiot now.
-
If it's any consolation I have been writing (sort of) C++ code for more than 20 years and still struggle with templates and lambdas. :((
Totally agree! :-D And I still avoid using lambdas as well. :~
-
Learning programmer need some help. I understand c++ Classes and I used to think I understood namespaces. But while trying to learn templates I'm getting kinda confused what is going on with this template example. template const CharT* std::basic_string< CharT, Traits, Alloc >::c_str() const [inline] //and later the definition of the member function c_str() const _CharT* c_str() const { return _M_data(); } (a) Do you call the first line the template declaration? (b) Do you call the second line the template implementation or definition? (c) It appears to be a scope resolution :: to the member function c_str() but what is the [inline] bracket syntax? (d)Also I assume the < CharT, Traits, Alloc > are defined in the header (elsewhere) with some value (overloaded or not)? Just anywhere you can illuminate what I'm missing on the concept.
Rw237 wrote:
(c) It appears to be a scope resolution :: to the member function c_str() but what is the [inline] bracket syntax?
Where did you get this template example from? The only place I've found the
[inline]
syntax is [here](https://gcc.gnu.org/onlinedocs/gcc-4.6.3/libstdc++/api/a00259.html) (gcc 4.6.3 api docs). That syntax does not show up in the current API docs, nor does it show up in the libstdc++ sources for gcc 4.6.3 or gcc 8.2. It is also not described in the the MS c++ template docs or the template docs at cpprefereence.com. I'm thinking that's a documentation note that c_str() may be declared as an inline function, much the same as the man page for a utility might show optional parameters e.g.find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]
-
Rw237 wrote:
(c) It appears to be a scope resolution :: to the member function c_str() but what is the [inline] bracket syntax?
Where did you get this template example from? The only place I've found the
[inline]
syntax is [here](https://gcc.gnu.org/onlinedocs/gcc-4.6.3/libstdc++/api/a00259.html) (gcc 4.6.3 api docs). That syntax does not show up in the current API docs, nor does it show up in the libstdc++ sources for gcc 4.6.3 or gcc 8.2. It is also not described in the the MS c++ template docs or the template docs at cpprefereence.com. I'm thinking that's a documentation note that c_str() may be declared as an inline function, much the same as the man page for a utility might show optional parameters e.g.find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]
-
If it's any consolation I have been writing (sort of) C++ code for more than 20 years and still struggle with templates and lambdas. :((