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

    Pass arguments to typedef?

    I am typedefing a boost::multi_array as follows:
    Code:
    typedef boost::multi_array<int, 3> _3DArray;
    If I wanted to be able to choose what type to make that _3DArray, what would I have to do? I was imagining something along the lines of:
    Code:
    typedef boost::multi_array<typename t, 3> _3DArray<typename t>;
    where you would simply declare the _3DArray with your chosen type. Obviously, this code does not work. How would I actually do this?
    Thank you in advance

  2. #2
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: Pass arguments to typedef?

    That is a 'template typedef'. Up until C++0x they didn't exist, and I am not sure if they exist in C++0x either. They can be simulated somewhat, details here and here.
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Pass arguments to typedef?

    It''s called a template alias in C++0x. Few compilers support it.

    However, you can do this:
    Code:
    template <typename T>
    struct MyArray3D: private boost::multi_array<T,3>
    {
    
    }
    Note, you'll need to define all the constructors you want to use, and a few other operations in order for this to work as a drop-in. But it is doable.

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