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. How to store a put a template class into a CList object?

How to store a put a template class into a CList object?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 3 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.
  • L Offline
    L Offline
    leonwoo
    wrote on last edited by
    #1

    hi, I have been trying to include a template class into a CList object but i it does not seem to work. I have tried to put in this way in the "Population" class: Typedef Chromosome chromosome CList PopulationArray; Is there any way to put a template class into another template class?? I appreciate your help. Thank you. leonwoo

    W M 2 Replies Last reply
    0
    • L leonwoo

      hi, I have been trying to include a template class into a CList object but i it does not seem to work. I have tried to put in this way in the "Population" class: Typedef Chromosome chromosome CList PopulationArray; Is there any way to put a template class into another template class?? I appreciate your help. Thank you. leonwoo

      W Offline
      W Offline
      Walter Gildersleeve
      wrote on last edited by
      #2

      I'm not having problems inserting template classes in a CList: template class Cell { public : T SetData(const T& t) { T old = data; data = t; return old; } T GetData() const { return data; } private : T data; }; CList, Cell > lst;//NOTE--there *must* be a space between the right-most braces : > > lst. Walter Gildersleeve Freiburg, Germany walter.gildersleeve@pe-gmbh.de

      L 1 Reply Last reply
      0
      • L leonwoo

        hi, I have been trying to include a template class into a CList object but i it does not seem to work. I have tried to put in this way in the "Population" class: Typedef Chromosome chromosome CList PopulationArray; Is there any way to put a template class into another template class?? I appreciate your help. Thank you. leonwoo

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        typedef Chromosome<CGene> chromosome;
        CList<chromosome,chromosome> PopulationArray;

        This should work fine. What error messages are you getting when you try this? --Mike-- http://home.inreach.com/mdunn/ Time is an illusion; lunchtime doubly so.

        L 1 Reply Last reply
        0
        • M Michael Dunn

          typedef Chromosome<CGene> chromosome;
          CList<chromosome,chromosome> PopulationArray;

          This should work fine. What error messages are you getting when you try this? --Mike-- http://home.inreach.com/mdunn/ Time is an illusion; lunchtime doubly so.

          L Offline
          L Offline
          leonwoo
          wrote on last edited by
          #4

          Thanks for your reply, The error message that i've got is "no copy constructor to copy the data type Chromosome". For now i can't remember the complete message but i will put it in after i've copied the message. :) leonwoo

          M 1 Reply Last reply
          0
          • W Walter Gildersleeve

            I'm not having problems inserting template classes in a CList: template class Cell { public : T SetData(const T& t) { T old = data; data = t; return old; } T GetData() const { return data; } private : T data; }; CList, Cell > lst;//NOTE--there *must* be a space between the right-most braces : > > lst. Walter Gildersleeve Freiburg, Germany walter.gildersleeve@pe-gmbh.de

            L Offline
            L Offline
            leonwoo
            wrote on last edited by
            #5

            Thanks for your reply Walter, can you please clarify what it means by CList ,Cell >1st.......>>1st thank you :) leonwoo

            1 Reply Last reply
            0
            • L leonwoo

              Thanks for your reply, The error message that i've got is "no copy constructor to copy the data type Chromosome". For now i can't remember the complete message but i will put it in after i've copied the message. :) leonwoo

              M Offline
              M Offline
              Michael Dunn
              wrote on last edited by
              #6

              Then you need to write a copy constructor. :cool: --Mike-- http://home.inreach.com/mdunn/ Time is an illusion; lunchtime doubly so.

              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