#include <set>
#include <string>
using namespace std;
struct StudInfo{ //declaration of structure
string name;
int id;
};
int compareID(StudInfo a , StudInfo b){ //Compare function as a parameter
if(a.id == b.id) return 0; //that is being passed to the set s
if(a.id < b.id) return -1;
else return 1;
}
int main(){
set<StudInfo> s(CompareID);
return 0;
}
在main()范围内我收到此错误(错误C2065:'CompareID':未声明的标识符)虽然相同的代码已成功编译 在编写此代码的视频讲座中请帮助。
答案 0 :(得分:0)
编程的黄金法则:99.9%的编译器错误是由于你,不是编译器。
尽管在视频讲座中成功编译了相同的代码 其中编写此代码
不,没有!
我怎么知道?嗯,这很简单。首先,我忽略了编译器出错的任何可能性。然后,我可以专注于源代码,和编译器输出。
解决方案很简单:将init: ## _Command call():_
init: _method start:_ getOrInitGit
init: _ looking for git folder in /home/work/projects/my-application _
init: _ found existing git folder _
: _method END:_
GitHelper: _method start:_ remoteBranchExists
GitHelper: _ checking for branch: master _
GitHelper: _ got 29 remote refs _
GitHelper: _ ref name: refs/remotes/origin/1.0.x _
GitHelper: _ ref simple name: 1.0.x _
GitHelper: _ simple name equals branch? false _
GitHelper: _ ref name: refs/remotes/origin/1.1.x _
GitHelper: _ ref simple name: 1.1.x _
GitHelper: _ simple name equals branch? false _
GitHelper: _ ref name: refs/remotes/origin/1.2.x _
GitHelper: _ ref simple name: 1.2.x _
GitHelper: _ simple name equals branch? false _
GitHelper: _ ref name: refs/remotes/origin/master _
GitHelper: _ ref simple name: master _
GitHelper: _ simple name equals branch? true _
: _method END:_
GitHelper: _method start:_ remoteBranchExists
GitHelper: _ checking for branch: develop _
GitHelper: _ got 29 remote refs _
GitHelper: _ ref name: refs/remotes/origin/1.0.x _
GitHelper: _ ref simple name: 1.0.x _
GitHelper: _ simple name equals branch? false _
GitHelper: _ ref name: refs/remotes/origin/1.1.x _
GitHelper: _ ref simple name: 1.1.x _
GitHelper: _ simple name equals branch? true _
: _method END:_
# JGitFlow Log - Wed Oct 05 2016 12:25:34 IST
## Configuration
JGit Version: 3.0.0.201306101825-r
JGitFlow Version: 0.21
Master name: master
Origin master exists = true
Develop name: develop
Origin develop exists = true
feature name: feature/
release name: release/
hotfix name: hotfix/
support name: support/
versiontag name:
--------------------------------------------------------------------------------
DefaultFlowFeatureManager: _ # Maven JGitFlow Plugin _
DefaultFlowFeatureManager: _
_
DefaultFlowFeatureManager: _ ## Configuration _
DefaultFlowFeatureManager: _
_
DefaultFlowFeatureManager: _ Maven Version: 3.3.9 _
DefaultFlowFeatureManager: _
_
DefaultFlowFeatureManager: _ Maven JGitFlow Plugin Version: 1.0 _
DefaultFlowFeatureManager: _
_
DefaultFlowFeatureManager: _ args: _
DefaultFlowFeatureManager: _ base dir: /home/work/project/myapplication _
DefaultFlowFeatureManager: _ default development version: null _
DefaultFlowFeatureManager: _ default feature name: null _
DefaultFlowFeatureManager: _ default release version: null _
DefaultFlowFeatureManager: _ release branch version suffix: release _
DefaultFlowFeatureManager: _ tag message: tagging release ${version} _
DefaultFlowFeatureManager: _ allow snapshots: false _
DefaultFlowFeatureManager: _ auto version submodules: false _
DefaultFlowFeatureManager: _ enable feature versions: true _
DefaultFlowFeatureManager: _ enable ssh agent: true _
DefaultFlowFeatureManager: _ feature rebase: false _
DefaultFlowFeatureManager: _ interactive: true _
DefaultFlowFeatureManager: _ keep branch: false _
DefaultFlowFeatureManager: _ no build: false _
DefaultFlowFeatureManager: _ no deploy: false _
DefaultFlowFeatureManager: _ no tag: false _
DefaultFlowFeatureManager: _ pushFeatures: true _
DefaultFlowFeatureManager: _ pushReleases: false _
DefaultFlowFeatureManager: _ pushHotfixes: false _
DefaultFlowFeatureManager: _ squash: false _
DefaultFlowFeatureManager: _ update dependencies: true _
DefaultFlowFeatureManager: _ use release profile: true _
DefaultFlowFeatureManager: _
--------------------------------------------------------------------------------
_
DefaultProjectHelper: _ installing ssh console credentials provider _
DefaultProjectHelper: _ installing ssh-agent credentials provider _
替换为set<StudInfo> s(CompareID);
。仔细注意这个案例。
完成编译工作。
然后我们可以继续您的运行时行为。您的比较器功能未正确指定;你需要用
替换这个功能set<StudInfo> s(compareID);
对于bool compareID(const StudInfo& a, const StudInfo& b){
return a.id < b.id;
}
小于false
的所有情况,比较器必须返回a.id
。注意我通过b.id
引用传递参数以避免不必要的字符串副本。