Creating a type alias for a templated class

后端 未结 3 1781
小鲜肉
小鲜肉 2020-12-31 16:35

Instead of using

std::vector ObjectArray;


I would like it to be

MyArray ObjectArray;

3条回答
  •  情歌与酒
    2020-12-31 16:51

    What you would really want is a templated typedef. Unfortunately those are not supported in the current version of C++, but they will be added in C++0x.

    For now, here's a possible workaround:

    template struct My {
        typedef std::vector Array;
    };
    
    My::Array ObjectArray
    
    
    

    Whether or not that is better than simply using std::vector directly, I'll leave to you to decide.

    提交回复
    热议问题