从两个声明之间的元编程前景来看,是否存在差异?
template<typename T>
struct matrix {
typedef matrix self_type; // or
typedef matrix<T> self_type;
};
Run Code Online (Sandbox Code Playgroud)
谢谢
在这种特殊情况下(在类模板中),matrix是一种简写matrix<T>.当你整天写出大量毛茸茸的模板,同时试图将所有东西都装在80列中时,欢迎使用速记.
请注意,您还可以缩写方法参数:
template <typename T>
struct matrix
{
typedef matrix my_type;
matrix(); // constructor is abbreviated too
matrix& operator=(matrix);
};
// Method argument types can be abbreviated too
// but not result types.
template <typename T>
matrix<T>& matrix<T>::operator=(matrix m)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
401 次 |
| 最近记录: |