【发布时间】:2014-02-24 02:32:28
【问题描述】:
我目前正在尝试在向量 V 中查找一个元素。 但我得到了很多错误。
bool VNS::remove(const HostName& name){ ^ 在 /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/algorithm:62:0 包含的文件中, 来自 vns.cc:2:.....
bool VNS::remove(const HostName& name){
auto it=find_if(v.begin(),v.end(),[](const HostName& a, const HostName& b){return a==b;});
//code that will remove the elem.
if(it!=v.end()){
return true;
}else{
return false;
}
}
HeaderFile:
class VNS:public NameServerInterface{
public:
/*
* Insert a name/address pair. Does not check if the name
* or address already exists.
*/
virtual void insert(const HostName&, const IPAddress&);
/*
* Remove the pair with the specified host name. Returns true
* if the host name existed and the pair was removed, false
* otherwise.
*/
virtual bool remove(const HostName&);
/*
* Find the IP address for the specified host name. Returns
* NON_EXISTING_ADDRESS if the host name wasn't in the name
* server.
*/
virtual IPAddress lookup(const HostName&) const;
private:
std::vector<std::pair<HostName,IPAddress> > v;
};
界面:
/*
* Interface NameServerInterface -- all name server implementations must
* implement this interface.
*/
#ifndef NAME_SERVER_INTERFACE_H
#define NAME_SERVER_INTERFACE_H
#include <string>
using HostName = std::string;
using IPAddress = unsigned int;
const IPAddress NON_EXISTING_ADDRESS = 0;
class NameServerInterface {
public:
virtual ~NameServerInterface() = default;
/*
* Insert a name/address pair. Does not check if the name
* or address already exists.
*/
virtual void insert(const HostName&, const IPAddress&) = 0;
/*
* Remove the pair with the specified host name. Returns true
* if the host name existed and the pair was removed, false
* otherwise.
*/
virtual bool remove(const HostName&) = 0;
/*
* Find the IP address for the specified host name. Returns
* NON_EXISTING_ADDRESS if the host name wasn't in the name
* server.
*/
virtual IPAddress lookup(const HostName&) const = 0;
};
#endif
我的 lambda exp 有两个参数。编译器如何知道它应该如何用正确的值替换它们。
【问题讨论】:
-
您希望
std::find_if作为值传入什么?
标签: c++