CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2005
    Posts
    382

    template parameter representation

    Consider the source snippet

    Code:
     
    typedef hw_default < volatile unsigned short > hw_default_type;
     
    typedef hw_register_struct < volatile unsigned short,
                                 some_other_policy < unsigned short >,
                                 0x500, 
                                 0 > hw_register_struct_type;
     
    int main() 
    {
      unsigned short aa ( 0 );
      foo < volatile unsigned short, 5, 6 > aa5_6 ( aa );
     
      hw_default_type ab ; 
      foo < hw_default_type, 5, 6 > ab5_6 ( ab );
     
      //hw_register_struct_type ac ; 
      //foo < hw_register_struct_type, 5, 6 > ac5_6 ( ac );
     
    }
    The code today is not extensible because it's structured around the default - hw_default_type which works for 'most' cases. I'm trying to modify source such that I could use the composite type hw_register_struct_type (commented out in main) and hw_default_type as parameters within the same code base. How could I achieve this?
    Last edited by mop65715; November 14th, 2009 at 04:15 PM. Reason: Removed alot of the source since I found a solution and I'm unable to delete question. The solution implement a new trait

  2. #2
    Join Date
    Feb 2009
    Posts
    326

    Re: template parameter representation

    would it be possible to post a minimum code to make it compile.

    I had built my own skeleton classes to make the code compile, given below is the example.

    For me it compiles ok, after uncommenting the lines:

    Code:
    template<typename T>
    class hw_default
    {};
    
    template<typename T1, typename T2, int, int>
    class hw_register_struct
    {};
    
    template<typename T>
    class some_other_policy
    {};
    
    typedef hw_default < volatile unsigned short > hw_default_type;
    
    template<typename T1, int, int>
    class foo
    {
        public:
            foo(T1) {};
    };
    
    
    
    typedef hw_register_struct < volatile unsigned short,
                                 some_other_policy < unsigned short >,
                                 0x500, 
                                 0 > hw_register_struct_type;
    
    int main() 
    {
    	unsigned short aa ( 0 );
    	
    
        foo < volatile unsigned short, 5, 6 > aa5_6 ( aa );
    	
    	hw_default_type ab ; 
    	foo < hw_default_type, 5, 6 > ab5_6 ( ab );
    	
    	hw_register_struct_type ac ; 
    	foo < hw_register_struct_type, 5, 6 > ac5_6 ( ac );
    	
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured