模版小结

1.模版函数,模版类都可以只声明,不定义


//这个地方必须声明,不然编译错误
template <typename Functor>
class RunnableAdapter;


template <typename R>
class RunnableAdapter<R(*)()> {
 public:
  typedef R (RunType)();


  explicit RunnableAdapter(R(*function)())
      : function_(function) {
  }


  R Run() {
    return function_();
  }


 private:
  R (*function_)();
};




int test1( void )
{
cout << "i is " << endl;
return 3;
}


void main()
{
int i = 23;
RunnableAdapter<int(*)(void)> ra(test1);
ra.Run();
}

你可能感兴趣的:(模版小结)