如何正确使用模板?我有一个数据类型问题与模板<> [英] How do I use templating properly? I'm having a data type issue with a template<>

查看:103
本文介绍了如何正确使用模板?我有一个数据类型问题与模板<>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EDIT 11/3/2011 9:37 pm:

这是我的错误:

 error: no matching function for call to "charList_join(const char [1], CISP430_A5::linked_list<char>&)"

这是我的原型:

template <typename Item>
string charList_join(const char* glue, linked_list<char> pieces);

这是我的函数调用:

charList_join("", usedChars)

static linked_list< char> 在调用 charList_join()的同一范围内声明。

where usedChars is a static linked_list<char> declared in the same scope where charList_join() is called.

EDIT 11/4/2011 8:45 am:好的,这里是我删除了不必要的函数的代码:

EDIT 11/4/2011 8:45am: Ok, so here is my code with unnecessary functions removed:

[ sehe:edited from pastebin to github ]

  • browse it online at github
  • download it with git:

 git clone git://gist.github.com/1340832.git


我得到了premute_append第57行第68列的错误。 cpp。我已经包括了makefile,所以你可以尝试建立它,如果你想要的。我现在只得到一个错误,但我只是不知道这是什么意思。

I'm getting the error on line 57, column 68 of premute_append.cpp. I've included the makefile so you can attempt to build it if you want. I'm only getting one single error at this point, but I just don't have any idea what it means.

如果你尝试编译错误将看起来像这:

If you try to compile the error will look like this:

[cisw320b_stu022@scc-bdiv-cis assn5]$ make
g++ -c main.cpp
g++ -c permute_append.cpp
permute_append.cpp: In member function âCISP430_A5::linked_list<std::basic_string<char> > CISP430_A5::permute_append::permute(CISP430_A5::linked_list<char>)â:
permute_append.cpp:57:68: error: no matching function for call to âcharList_join(const char [1], CISP430_A5::linked_list<char>&)â
make: *** [permute_append.o] Error 1

任何想法为什么我得到这个错误?

Any idea why I'm getting this error?

推荐答案

string charList_join(const char* glue, linked_list<char> pieces);

实际上是

template< typename Item >
string charList_join(const char* glue, linked_list<char> pieces);

由于项目应该明确传递参数:

Since Item is not detected from any of the arguments, you should pass it explicitly:

charList_join<SomeItemType>( "", usedChars);

或者您只是想要:

template< typename Item >
string charList_join(const char* glue, linked_list<Item> pieces);

这篇关于如何正确使用模板?我有一个数据类型问题与模板&lt;&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆