【发布时间】:2015-04-29 23:19:58
【问题描述】:
只花了大约一个小时试图弄清楚为什么当我尝试构建以下类(在 XCode 中)时会收到 20 条 "Semantic issue - no matching function for call to 'swap'" 类型的错误消息。
test.h
#include <iostream>
#include <string>
#include <vector>
class Test{
std::vector<std::string> list;
void run() const;
static bool algo(const std::string &str1, const std::string &str2);
};
test.cpp
#include "test.h"
void Test::run() const {
std::sort( list.begin(), list.end(), algo );
}
bool Test::algo(const std::string &str1, const std::string &str2){
// Compare and return bool
}
大多数遇到相同问题的人似乎都将他们的算法设为类成员而不是静态成员,但这显然不是这里的问题。
【问题讨论】:
标签: c++ xcode sorting compiler-errors swap