C_and_CPP 板


LINE

开发平台(Platform): (Ex: Win10, Linux, ...) linux 编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出) 额外使用到的函数库(Library Used): (Ex: OpenGL, ...) 问题(Question): 大家好,刚接触C++没多久(以前学c),还不太熟悉请多指教。 编译完後出现一群undefined reference to, 我觉得应该是在讲class R的问题,可是检查了R找不出错在哪... 详细状况如下: /tmp/ccY2jGY2.o: In function `R::R(int, int)': test.cpp:(.text._ZN1RC2Eii[_ZN1RC5Eii]+0x13): undefined reference to `R::r1' test.cpp:(.text._ZN1RC2Eii[_ZN1RC5Eii]+0x1c): undefined reference to `R::r2' /tmp/ccY2jGY2.o: In function `R::now()': test.cpp:(.text._ZN1R3nowEv[_ZN1R3nowEv]+0x10): undefined reference to `R::r1' /tmp/ccY2jGY2.o: In function `R::Ans(float)': test.cpp:(.text._ZN1R3AnsEf[_ZN1R3AnsEf]+0x68): undefined reference to `R::s' test.cpp:(.text._ZN1R3AnsEf[_ZN1R3AnsEf]+0x6e): undefined reference to `R::r1' test.cpp:(.text._ZN1R3AnsEf[_ZN1R3AnsEf]+0x7f): undefined reference to `R::s' test.cpp:(.text._ZN1R3AnsEf[_ZN1R3AnsEf]+0x90): undefined reference to `R::r2' test.cpp:(.text._ZN1R3AnsEf[_ZN1R3AnsEf]+0x96): undefined reference to `R::r1' test.cpp:(.text._ZN1R3AnsEf[_ZN1R3AnsEf]+0xff): undefined reference to `R::r1' test.cpp:(.text._ZN1R3AnsEf[_ZN1R3AnsEf]+0x105): undefined reference to `R::r1' collect2: error: ld returned 1 exit status 喂入的资料(Input): 预期的正确结果(Expected Output): 错误结果(Wrong Output): 程式码(Code):(请善用置底文网页, 记得排版) codePad:https://codepad.remoteinterview.io/HUAVHCNAJT #include <iostream> #include <cmath> #include <cstdlib> # include <iostream> # include <string> # include <fstream> using namespace std; //专门拿来算R的class class R{ public: int ans;//所求 R(){ cerr<<"no data to calculate"; } R(int r1_,int r2_){ r1=r1_; r2=r2_; } //还没有输入s值的R值 int now(){ ans=r1; return ans; } //有输入s的R值 int Ans(float s_){ //s 只有三种:1 ,0 ,0.5 if (s_==1||s_==0||s_==0.5){ s=s_; } else{ cerr<<"need to be 1 0.5 0"; exit(1); } r1=r1+k*(s-(1/(1+pow(10,(r2 - r1/400))))); //R的计算公式 ans=r1; return ans; } private: static int r1,r2; static float s; static const int k=32; }; int main(){ ofstream outFile("filein.txt",ios::out);//先做一个filein.txt if(!outFile) { cerr<<"err\n"; exit(1); } //输入原始数据 outFile << "k\tr1\tr2\n"; outFile << 32<<"\t"<<1613<<"\t"<<1609<<endl; outFile << "sa\tsb\n"; outFile << 0 <<"\t"<< (1-0)<<"\t"<<endl; outFile << 0.5 <<"\t"<< (1-0.5)<<"\t"<<endl; outFile << 0.5 <<"\t"<< (1-0.5)<<"\t"<<endl; outFile << 0 <<"\t"<< (1-0)<<"\t"<<endl; outFile << 0 <<"\t"<< (1-0)<<"\t"<<endl; outFile << 0 <<"\t"<< (1-0)<<"\t"<<endl; outFile.close(); //接下来要开始读filein,txt,然後写一个fileout.txt //宣告,等一下会用到 string headline1, headline2; int r1,r2,k; float pointa,pointb;//s值 ifstream inFile("filein.txt",ios::in); ofstream ouFile("fileout.txt",ios::out); //成功? if(!inFile){ cerr<<"filein.txt fail"; exit(1); } if(!ouFile){ cerr<<"fileout.txt fail"; exit(1); } //开始读档 getline(inFile,headline1); inFile>>k>>r1>>r2; R ra(r1,r2); //初始化ra R rb(r2,r1); //初始化rb ouFile<< ra.now()<<"\t"<< rb.now()<<"\n"; //ra rb原封不动写入fileout.txt //开始读s值 while(inFile>>pointa>>pointb){ ouFile<< ra.Ans(pointa)<<"\t"<< rb.Ans(pointb)<<"\n"; //算一算写入fileout.txt// } inFile.close(); ouFile.close(); } 补充说明(Supplement):*[m 这里的R是在算Elo rate。 s是指每次胜负的得分。赢者得一分,输了零分,平手0. 5 研究了很久都不了,拜托帮忙了 --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 218.164.190.214
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1490905771.A.9FB.html ※ 编辑: franklin1997 (218.164.190.214), 03/31/2017 04:34:08 ※ 编辑: franklin1997 (218.164.190.214), 03/31/2017 04:34:49
1F:推 steve1012: 你需要 init static data member 吧 03/31 04:37
2F:→ steve1012: 找个地方初始化你class 的r1 03/31 04:38
3F:推 steve1012: 话说static 真的是你要的吗 03/31 04:39
呃 应该是不用没错(打程式的时候自己混乱了 我睡一下再改改看 甘温 ※ 编辑: franklin1997 (36.238.194.129), 03/31/2017 05:00:50
4F:推 loveflames: 问题有够明显,static data member写在类里面只是声 03/31 07:30
5F:→ loveflames: 明,非定义 03/31 07:30
我把那两个static删掉了,谢谢两位大大 ※ 编辑: franklin1997 (36.238.194.129), 03/31/2017 11:28:37
6F:推 HMKRL: 难怪我觉得这问题好眼熟XDD 这是算elo的对吧XDD 04/07 03:00







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Tech_Job站内搜寻

TOP