jus*_*tik 5 c++ templates struct parameter-passing inner-classes
存在包含内部结构TIn的结构TOut:
template <typename T>
struct TOut
{
struct TIn
{
bool b;
};
TIn in;
T t;
};
Run Code Online (Sandbox Code Playgroud)
如何正确传递TIn作为某种方法的形式参数?
class Test
{
public:
template <typename T>
static void test ( const TOut<T>::TIn &i) {} //Error
};
int main()
{
TOut <double> o;
Test::test(o.in);
}
Run Code Online (Sandbox Code Playgroud)
该程序编译时出现以下错误:
Error 4 error C2998: 'int test' : cannot be a template definition
Run Code Online (Sandbox Code Playgroud)
您需要使用typename关键字:
template <typename T>
static void test ( const typename TOut<T>::TIn &i) {}
Run Code Online (Sandbox Code Playgroud)
看看我在哪里以及为什么要放置"template"和"typename"关键字?