未能推断出模板参数,求调试成功!
#include <iostream>
#include <vector>
#include <functional>
#include <string>
using namespace std;
class A
{
public:
string name;
void print(ostream& out) const
{
out << name << endl;
}
};
ostream& operator<<(ostream& out, const A& a)
{
a.print(out);
return out;
}
template <typename T, typename T1>
const T& findMax(const vector<T> & a, T1 b = less<T1>)
{
int maxIndex = 0;
for(int i = 1; i != a.size(); ++i)
{
if(b(a[maxIndex], a[i]))
{
maxIndex = i;
}
}
return a[maxIndex];
}
class B
{
public:
bool operator()(const string& a, const string& b) const
{
return _stricmp(a.c_str(), b.c_str()) < 0;
}
};
int main()
{
vector<A> a(3);
a[0].name = "A";
a[1].name = "a";
a[2].name = "c";
cout << findMax(a) << endl;
cout << findMax(a,B()) << endl;
}
#include <vector>
#include <functional>
#include <string>
using namespace std;
class A
{
public:
string name;
void print(ostream& out) const
{
out << name << endl;
}
};
ostream& operator<<(ostream& out, const A& a)
{
a.print(out);
return out;
}
template <typename T, typename T1>
const T& findMax(const vector<T> & a, T1 b = less<T1>)
{
int maxIndex = 0;
for(int i = 1; i != a.size(); ++i)
{
if(b(a[maxIndex], a[i]))
{
maxIndex = i;
}
}
return a[maxIndex];
}
class B
{
public:
bool operator()(const string& a, const string& b) const
{
return _stricmp(a.c_str(), b.c_str()) < 0;
}
};
int main()
{
vector<A> a(3);
a[0].name = "A";
a[1].name = "a";
a[2].name = "c";
cout << findMax(a) << endl;
cout << findMax(a,B()) << endl;
}
...全文
相关推荐
vs2010未能将脚本调试器附加到计算机上的进程。已附加了一个调试器
突然用着vs就不能用了,找了一晚上才找到解决方法,对于对初学的菜鸟很有帮助,简介明了。 vs2010未能将脚本调试器附加到计算机上的进程。已附加了一个调试器
模板调试的艺术与挑战
本文深入探讨了C++模板编程中的调试技巧,包括模板类实例化、静态成员函数与全局变量的处理,以及整数计算与引用常量的注意事项。同时,文章还涉及了一些常见的编译器错误和解决方案,以及确保代码可移植性的最佳实践。...
STM32F103C8T6移植freertos模板,测试成功!
本资源是STM32F103C8T6移植freertos模板,经过测试,功能正常,测试成功! 适用于项目初学,模板搭建,在此模板基础上开发完成其他项目。
无法在web服务器上启动调试。服务器因语法无效而未能处理调试请求。
无法在web服务器上启动调试。服务器因语法无效而未能处理调试请求。
nrf905收发程序!调试成功!愿意分享!
nrf905收发程序!调试成功!愿意分享!自己写的!注释很清楚!


