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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧