-
May 8th, 2011, 04:31 PM
#1
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
-
May 8th, 2011, 06:51 PM
#2
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.
-
May 8th, 2011, 07:21 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|