C++ template typedef
Mam klasę
template<size_t N, size_t M>
class Matrix {
// ....
};
Chcę utworzyć typedef
, który tworzy Vector
(wektor kolumnowy), który jest odpowiednikiem Matrix
o rozmiarach N I 1. Coś w tym stylu:
typedef Matrix<N,1> Vector<N>;
, który powoduje błąd kompilacji. Poniższe tworzy coś podobnego, ale nie dokładnie tego, czego chcę:
template <int N>
class Vector: public Matrix<N,1>
{ };
Czy istnieje rozwiązanie, czy też nie jest to zbyt kosztowne obejście / najlepsza praktyka?
314
Author: Benjamin Gruenbaum, 2010-05-08
2 answers
C++11 dodał deklaracje aliasów , które są uogólnieniem typedef
, pozwalając na szablony:
template <size_t N>
using Vector = Matrix<N, 1>;
Typ {[3] } jest równoważny Matrix<3, 1>
.
W C++03 najbliższe przybliżenie to:
template <size_t N>
struct Vector
{
typedef Matrix<N, 1> type;
};
Tutaj typ Vector<3>::type
jest równoważny Matrix<3, 1>
.
468
Author: GManNickG,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-11 19:28:31
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-11 19:28:31
Oto rozwiązanie C++0x:
template<size_t N>
class Vector: public Matrix<N,1>{};
-1
Author: Rchn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-10-05 15:20:38
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-10-05 15:20:38