+ -
当前位置:首页 → 问答吧 → 问下关于模板函数重载的问题

问下关于模板函数重载的问题

时间:2010-09-20

来源:互联网

本帖最后由 zhanglistar 于 2010-09-20 16:26 编辑

代码如下
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;

  4. template <typename Comparable>
  5. void testa(vector<Comparable> &a)
  6. {
  7.     bool value = false;
  8.     testa(a, value);
  9. }

  10. template <typename Comparable>
  11. void testa(vector<Comparable> &a, bool x)
  12. {

  13. }

  14. int main()
  15. {
  16.     vector<int> array;
  17.     testa(array);

  18.     return 0;
  19. }
复制代码
g++编译错误如下:
  1. calltemplate.cpp: In function ‘void testa(std::vector<Comparable, std::allocator<_CharT> >&) [with Comparable = int]’:
  2. calltemplate.cpp:21:   instantiated from here
  3. calltemplate.cpp:9: error: no matching function for call to ‘testa(std::vector<int, std::allocator<int> >&, bool&)’
复制代码
gcc4.2.4   
怎么用这个模板函数重载的呀????


sorry   是声明的问题。

今天有点2.。。。。。

作者: zhanglistar   发布时间: 2010-09-20

  1. template <typename Comparable>
  2. void testa(vector<Comparable> &a, bool x);

  3. template <typename Comparable>
  4. void testa(vector<Comparable> &a)
  5. {
  6.     bool value = false;
  7.     testa(a, value);
  8. }
复制代码
这样?

作者: OwnWaterloo   发布时间: 2010-09-20