2011-04-18 16 views
2

テンプレートパラメータにunsigned int型へのconst unsigned int型の変換

#include <iostream> 

template< class T, unsigned int NVectorDimension = 3 > 
class Vector 
{ 
}; 

template< unsigned int TDimension > 
int RunTest(void) 
{ 
    const unsigned int VectorDimension = 4; 
    typedef Vector< int, VectorDimension >  VectorPixelType; 
} 

int main(int argc, char *argv[]) 
{ 

    return 0; 
} 

私が取得:

In function ‘int RunTest()’: 
12:40: error: could not convert template argument ‘VectorDimension’ to ‘unsigned int’ 
error: invalid type in declaration before ‘;’ token 

任意のアイデアそれと間違っている何?

デビッド

+0

それはどのコンパイラですか? gccはそれを処理できます(値を返さないRunTest以外)。 – EboMike

+0

GCC 4.6。 GCC 4.4でうまくいきました。私はGCC 4.7でも動作しないと言われました。これらの新しいgccで動作するように変更するために私ができることは何か小さなものはありますか? –

+0

'RunTest'にreturn文がありませんが、このコードには何も間違いはありません: - /これはコンパイラのバグのようです(私はGCC Bugzillaデータベースを簡単に検索しましたが、誰か他の人が運が良いかもしれない)。 'typedef Vector < int, 4 > VectorPixelType;は動作しますか? –

答えて

0

コメントによると、うまくいくはずです。それ以外の場合は、class Vectorの宣言を少し変更するのが手頃ですか?試してみることができます。

template< class T, const unsigned int NVectorDimension = 3 > 
class Vector // ^^^^^ adding const here 
{ 
}; 

これでうまくいかない場合、マクロ回避策を最後の手段として試すことができます。

int RunTest(void) 
{ 
#define VectorDimension 4 
    typedef Vector< int, VectorDimension >  VectorPixelType; 
    // ... 
#undef VectorDimension 
} 
+0

フム、: の#include テンプレートを<クラスT、CONST unsigned int型NVectorDimension = 3> クラスベクトル {}。 テンプレート void RunTest(void) { const unsigned int VectorDimension = 4; typedefベクトル VectorPixelType; (int argc、char * argv []) { return 0; } –

+0

'VectorDimension'はRunTestのローカルなので、編集したコードに表示されるように' #define 'できますか? – iammilind

関連する問題