Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. template confusion

template confusion

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++wpfhelptutorial
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rw237
    wrote on last edited by
    #1

    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.

    R K 2 Replies Last reply
    0
    • R Rw237

      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.

      R Offline
      R Offline
      Rw237
      wrote on last edited by
      #2

      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.

      L 1 Reply Last reply
      0
      • R Rw237

        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.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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. :((

        V R 2 Replies Last reply
        0
        • L Lost User

          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. :((

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          Totally agree! :-D And I still avoid using lambdas as well. :~

          1 Reply Last reply
          0
          • R Rw237

            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.

            K Offline
            K Offline
            k5054
            wrote on last edited by
            #5

            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]

            R 1 Reply Last reply
            0
            • K k5054

              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]

              R Offline
              R Offline
              Rw237
              wrote on last edited by
              #6

              Thanks k5054, that must be it. Probably only novice learning dummies like me fail to ascertain that. You have cleared up my confusion and I can stop searching for this new mysterious syntax that I've never seen before.

              1 Reply Last reply
              0
              • L Lost User

                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. :((

                R Offline
                R Offline
                Rw237
                wrote on last edited by
                #7

                Thanks Richard and Victor for the consolations. This is a much nicer forum than some. I do try to research before posting but sometimes without help I get stumped.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups