[問題] VC6, binary_function, and virtual

看板C_and_CPP (C/C++)作者 (darkpoet)時間16年前 (2009/06/13 15:04), 編輯推噓4(404)
留言8則, 4人參與, 最新討論串1/1
各位板友好,下面的程式碼我在 VC6 上面執行會當掉,在 DevC++4980 不會。 在 VC6 上面只要將紫色部份任選一個刪除就可以正常執行, 請教各位大大,這是我的程式碼有錯或是 VC6 的問題呢? 謝謝大家的幫忙! Orz #include <functional> using std::binary_function; #include <vector> using std::vector; #include <algorithm> using std::sort; class CSmaller : public binary_function<int, int, bool> { public: virtual bool operator()(int lhs, int rhs) const { return lhs < rhs; } }; int main() { vector <int> pop(17, 1); sort(pop.begin(), pop.end(), CSmaller()); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.149.152

06/13 15:08, , 1F
VC9,可編譯執行無誤
06/13 15:08, 1F

06/13 15:40, , 2F
VC6的問題 太老舊了.....
06/13 15:40, 2F

06/13 15:44, , 3F
請養成好習慣,不要在 #include 前寫 using
06/13 15:44, 3F

06/13 16:20, , 4F
感謝大家的回覆!之前好像有看過文章提到 ls 大說的好習
06/13 16:20, 4F

06/13 16:21, , 5F
慣,不過忘記理由是什麼了,可以請 ls 大補充一下嗎?Orz
06/13 16:21, 5F

06/13 16:41, , 6F
我只想得到一點,你在#include <iostream>之前就在使用 using
06/13 16:41, 6F

06/13 16:41, , 7F
namespace std;但這時候編譯器根本不認識std。另外應該還有
06/13 16:41, 7F

06/13 16:42, , 8F
衝突的問題,以前似乎有遇過一次,但沒仔細追蹤
06/13 16:42, 8F
文章代碼(AID): #1ACqzmqF (C_and_CPP)
文章代碼(AID): #1ACqzmqF (C_and_CPP)