2014-09-24 131 views
1

我正在嘗試爲快速樓層創建模板。C++ fast floor模板:Windows上的Visual Studio出現C4430錯誤

而且我有一個模板的下面的開始,但是當我在Windows下編譯有關在我的代碼中使用IN和OUT時,我收到一個錯誤。任何幫助,將不勝感激。提前致謝!

template<typename IN, typename OUT> 
class FastConversion { 
    public: 
     FastConversion() { 
      // empty 
     } 

     // rounds to the next lowest whole number 
     //  1.5 --> 1.0 
     // -1.5 --> -2.0 
     inline OUT floor(const IN& x) { 
      OUT output = 0; 
      // slowest version 
      #if defined(__APPLE__) || defined(__linux__) || defined(WIN64) 
       output = static_cast<OUT>(std::floor(static_cast<double>(x))); 
      #elif defined(WIN32) 
       __asm { 
        fld x; 
        fadd st, st(0); 
        fadd negOneHalf; 
        fistp i; 
        sar i, 1; 
       }; 
      #else 
       output = static_cast<OUT>(std::floor(static_cast<double>(x))); 
      #endif 
      return output; 
     } 
}; 

隨着調用爲:

inline i32 fastFloor(f64 x) { 
    FastConversion<f64, i32> f; 
    i32 floored = f.floor(x); 
    return floored; 
} 

注:123-132和F64的預期(int和double)。我在64位機器上運行32位編譯。我正在使用C++ - 11。我有一個CMake文件以及一個vcxproj文件。

與以下錯誤:

FastConversion.h(40): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 

我似乎可以編譯罰款與在Mac上鏗鏘,但是當我試圖與Visual Studio一樣,我結束了上述錯誤。

謝謝!

+1

類定義中有兩個未定義的變量:'negOneHalf'和'i'。當我定義這些和'typedef int i32; typedef double f64;'您的代碼在VC++ 2010上編譯時沒有錯誤。 – Rimas 2014-09-24 06:00:48

+2

只是一個側面問題,是什麼讓這個轉換變得更快? – user1767754 2014-09-24 06:07:36

+0

它使用'#include '編譯好VS2013和VS2010,用'double'搜索/替換'i32'並用'double'替換'f64'。這導致我懷疑'IN'和'OUT'與某處的預處理器定義有衝突。例如,如果將模板類型重命名爲「T」和「U」,它是否適用於您? – 2014-09-24 07:40:55

回答

1

它使用VS2013和VS2010只是#include <cmath>搜索/與INTF64更換123-132編譯罰款。這導致我懷疑INOUT與某些預處理器定義衝突某處。例如,如果將模板類型重命名爲TU,它是否適用於您?