storing datatypes (typedefs) inside template class

This is a discussion on storing datatypes (typedefs) inside template class within the C++ Programming forums, part of the General Programming Boards category; Hello Is it possible to do the following (without template argument list): Code: Registry::Inside::Type some_type; with this code: Code: template<class ...

  1. #1
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630

    storing datatypes (typedefs) inside template class

    Hello

    Is it possible to do the following (without template argument list):

    Code:
    Registry::Inside::Type some_type;
    with this code:

    Code:
    template<class T>
    struct Registry {
    	typedef std::map<std::string, T> Type;
    
    	struct Inside {
    		typedef std::string Type;
    	};
    };
    Ive been wondering if this is possible because I want to keep datatypes nicely organized in same classes so that I could do:

    Code:
    Registry::Inside::Type some_type;
    Registry<std::string>::Type some_other_type;
    Many thanks in advance!

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Yes... that should work fine (although you probably need a typename for the first one). Are you having problems?

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You cannot omit the template parameters of a template in naming a nested element unless you're within the implementation scope of the template.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 07-24-2006, 08:14 AM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Instantiating a template class
    By NullS in forum C++ Programming
    Replies: 11
    Last Post: 02-23-2005, 09:04 AM
  4. template functions inside a class
    By Trauts in forum C++ Programming
    Replies: 8
    Last Post: 03-12-2004, 09:05 PM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21