2013-04-03 93 views
0

看看這個樣品:克++錯誤:預期基本表達式

struct parent 
{ 
    template <typename t> 
    inline static t get_t(); 
}; 

struct child : public parent 
{ 
    template <typename t> 
    inline static t get_t() 
    { 
     return t(-1); 
    } 
}; 

template <typename t> 
struct call 
{ 
    inline static int get_value() 
    { 
     return t::get_t<int>(); 
    } 
}; 

typedef call<child> test; 

int main() 
{ 
    int v = test::get_value(); 
} 

的代碼編譯,錯誤如下:

In static member function 'static int call<t>::get_value()': 
    error: expected primary-expression before 'int' 
    error: expected ';' before 'int' 
    error: expected unqualified-id before '>' token 

當我編譯用Visual C++ 2008和英特爾C++它的代碼編譯沒有問題。

那是什麼意思?

+0

可能的重複[哪裏和爲什麼我必須把「模板」和「typename」關鍵字?](http://stackoverflow.com/questions/610245/where-and-why-do-i-have -to-把最模板和類型名稱的關鍵字) –

回答

0

只需添加

template

關鍵字:

template <typename t> 
struct call 
{ 
    inline static int get_value() 
    { 
     return t::template get_t<int>(); 
    } 
};