Degg0416 2016-12-18 02:11 采纳率: 0%
浏览 3831

C++ warning C4346 依赖名称不是类型

//编写一个函数模板
//该模板用于将l1链表的[p1,l1.end())区间和l2链表的[p2,l1.end())区间的内容交换。
//在主函数中调用该模板,以测试该模板的正确性
#include
#include
#include
using namespace std;

template
void exchange(list& l1, list::iterator p1, list& l2, list::iterator p2) {
listl3;
l3.splice(l3.begin(), l1, p1, l1.end());
l1.splice(l1.end(), l2, p2, l2.end());
l2.splice(l2.end(), l3, l3.begin(), l3.end());
}

int main()
{
int a[5] = { 1,2,3,4,5 };
int b[6] = { 10,11,12,13,14,15 };
listl1(a, a + 5);
listl2(b, b + 6);
cout << "l1 before exchange: ";
copy(l1.begin(), l1.end(), ostream_iterator(cout, " "));
cout << "l2 before exchange: ";
copy(l2.begin(), l2.end(), ostream_iterator(cout, " "));

list<int>::iterator iter1 = l1.begin();
advance(iter1, 3);
list<int>::iterator iter2 = l2.begin();
advance(iter2, 3);

exchange<int>(l1, iter1, l2, iter2);
cout << "l1 after exchange: ";
copy(l1.begin(), l1.end(), ostream_iterator<int>(cout, " "));
cout << "l2 after exchange: ";
copy(l2.begin(), l2.end(), ostream_iterator<int>(cout, " "));
return 0;

}

1>g:\c++\homework in book\10_6\10_6\10_6.cpp(12): warning C4346: “std::list>::iterator”: 依赖名称不是类型
1> g:\c++\homework in book\10_6\10_6\10_6.cpp(12): note: 用“typename”为前缀来表示类型
1>g:\c++\homework in book\10_6\10_6\10_6.cpp(12): error C2061: 语法错误: 标识符“iterator”
1>g:\c++\homework in book\10_6\10_6\10_6.cpp(35): error C2672: “exchange”: 未找到匹配的重载函数
1>g:\c++\homework in book\10_6\10_6\10_6.cpp(35): error C2780: “void exchange(std::list> &)”: 应输入 1 个参数,却提供了 4 个
1> g:\c++\homework in book\10_6\10_6\10_6.cpp(12): note: 参见“exchange”的声明
1>g:\c++\homework in book\10_6\10_6\10_6.cpp(35): error C2780: “_Ty std::exchange(_Ty &,_Other &&)”: 应输入 2 个参数,却提供了 4 个
1> d:\microsoft visual studio 14.0\vc\include\utility(590): note: 参见“std::exchange”的声明
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

  • 写回答

2条回答 默认 最新

  • dabocaiqq 2016-12-31 09:53
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 R语言 拟时序分析降维图如何减少分支
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统