2014-01-22 165 views
1

考慮以下測試特徵矩陣const型

Eigen::MatrixXd B(Eigen::MatrixXd::Random(5,5)); 
const Eigen::MatrixXd C(Eigen::MatrixXd::Random(5,5)); 
std::cout << "B " << typeid(B).name() << std::endl; 
std::cout << "C " << typeid(C).name() << std::endl; 
std::cout << " === " << std::endl; 
std::cout << "B.T " << typeid(B.transpose()).name() << std::endl; 
std::cout << "C.T " << typeid(C.transpose()).name() << std::endl; 

並且它的輸出爲何C未示出爲const

B N5Eigen6MatrixIdLin1ELin1ELi0ELin1ELin1EEE 
C N5Eigen6MatrixIdLin1ELin1ELi0ELin1ELin1EEE 
=== 
B.T N5Eigen9TransposeINS_6MatrixIdLin1ELin1ELi0ELin1ELin1EEEEE 
C.T N5Eigen9TransposeIKNS_6MatrixIdLin1ELin1ELi0ELin1ELin1EEEEE 

demangled

B Eigen::Matrix<double, -1, -1, 0, -1, -1> 
C Eigen::Matrix<double, -1, -1, 0, -1, -1> 
=== 
B.T Eigen::Transpose<Eigen::Matrix<double, -1, -1, 0, -1, -1> > 
C.T Eigen::Transpose<Eigen::Matrix<double, -1, -1, 0, -1, -1> const> 

? Eigen怎麼知道它是?這是一個Eigen問題還是這個typeid

+0

你能向我們展示潰敗的輸出嗎? –

+0

我不明白你能從中得到什麼,但爲什麼不... – yannick

回答

1

這是由於typeid行爲:

§5.2.8/ 5 [expr.typeid]的glvalue表達的頂層cv修飾符或型-ID那是typeid的操作數總是被忽略。

所以在這兩種情況下,typeid將只適用於Eigen::MatrixXd

+0

任何想法爲什麼他們添加了這樣一個奇怪的規則? – yannick