1
Header.h使用別名的顯式模板實例化?
template <int>
class FiniteElement
{
public:
int GetDOF();
};
using FiniteElement2D= FiniteElement<3>;
using FiniteElement3D= FiniteElement<6>;
Source.cpp
#include "Header.h"
//template class FiniteElement<3>;
//template class FiniteElement<6>;
template FiniteElement2D; // Using alias for explicit template instantiation !!!
template FiniteElement3D;
template <int DOF>
int FiniteElement<DOF>::GetDOF()
{ return DOF; }
Main.cpp的
#include "Header.h"
#include <iostream>
int main()
{
FiniteElement3D Elem;
std::cout << Elem.GetDOF();
return 0;
}
令我驚訝的是,上面的程序編譯,並與視覺鏈接Studio 2015 Update 3.我喜歡允許別名用於顯式模板實例化的想法,但它似乎不適用於gcc或clang。
它是即將到來的標準的特徵還是VS的特定特徵?
這未能與當前的Clang/C2(2016年7月)鏈接,但仍與當今的每日構建(v19.10.24606)鏈接。請[提交錯誤報告](https://connect.microsoft.com/VisualStudio/)並在此處發佈鏈接。 – ildjarn
@GuillaumeRacicot回想起來,很容易稱之爲「愚蠢」,現在很清楚的是一個糟糕的設計決定。 https://blogs.msdn.microsoft.com/vcblog/2015/09/25/rejuvenating-the-microsoft-cc-compiler/是的,VS仍然不符合,是的,所有其他主要編譯器都完全符合C + +14現在一段時間。但是你必須對他們的擁有權和(緩慢)進入正確的方向給予好評:https://blogs.msdn.microsoft.com/vcblog/2016/06/07/expression-sfinae-improvements-in-vs- 2015-update-3 /。他們(以及我們作爲用戶)正在爲很久以前犯的一個錯誤付錢 - **看起來是正確的**。 – bolov
@bolov是的,你是對的。我想我有今天的VS錯誤負載... –