今天我的一個朋友告訴我,下面的代碼編譯以及他的Visual Studio 2008:Visual C++編譯器允許從屬名稱作爲沒有「typename」的類型?
#include <vector>
struct A
{
static int const const_iterator = 100;
};
int i;
template <typename T>
void PrintAll(const T & obj)
{
T::const_iterator *i;
}
int main()
{
std::vector<int> v;
A a;
PrintAll(a);
PrintAll(v);
return 0;
}
我通常使用G ++,它總是拒絕通過第二PrintAll()調用。據我所知,對於這個問題,g ++正在做翻譯模板的標準方式。
那麼,我的知識是錯誤的,還是VS2008的擴展?
這是/ Za(嚴格)還是/ Ze(默認,擴展)? – MSalters 2010-06-04 15:23:22
@ MSalters:我剛剛嘗試過/ ZA。沒有看到任何區別... – hpsMouse 2010-06-04 15:56:04