Thread: Template confusion

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    19

    Template confusion

    Heya,

    How, or indeed can, I create a class containing an array of templated classes with different types?

    Umm, like maybe this-
    Code:
    template <class T> item{
        public:
            T data;
    };
    class container{
        public:
            void add(<class T>,T);
            item*<> items;
    };
    Where I could add to the items array with different types for each element, can I do this at all?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >can I do this at all?
    Not in a practical way. You'll want to redesign your code so that you can take advantage of polymorphism.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    19
    Ahh, perfect. I've rewritten it using polymorphism, and it's a lot more suited to my purpose anyway..

    Thanks a lot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM