Fuck Vc :: STL

xiaoxiao2021-03-06  70

Description: The STL library comes with the Fuck VC6. Question: struct test {test (int _nIndex): nindex (_nIndex) {} int NINDEX;}; list alist; Sort Test :: NINDEX from small to large to the elements in Alist. Solution: Solution 1, from the hot chicken. Make a Test * Wapper. # Include #include #include #include using namespace std;

Struct test {test (int _nIndex = 0) {nindex = _nIndex;} int nindex;

Class test_ptr {public: test_ptr (): PTR_ (0) {} test_ptr (TEST * P): PTR_ (P) {} public: BOOL Operator <(const test_ptr & x) const {return PTR_-> NINDEX NINDEX;} void print () {cout << ptr _-> nindex << endl;} private: Test * PTR_;

List alist;

Void Print () {list :: item Pos; for (POS = alist.begin (); pOS! = alist.end (); POS) {(* POS) .print ();}}

INT main () {alist.push_back (new test (15)); alist.push_back (new test (6)); alist.push_back (new test (32));

Print (); alist.sort (); print (); return 0;}, two, make a sorting interface. At first I used this method. But he cannot compile it under VC. // In DEV C via #include #include #include #include using namespace std;

Struct test {test (int _nIndex = 0) {nindex = _nIndex;} int nindex;

Class test_ptr_comp {public: BOOL Operator () (const test * const & x, const test * const & y) const {return x-> nindex nindex;}};

List alist;

Void Print () {list :: item Pos; for (POS = alist.begin (); pOS! = alist.end (); pos) {cout << (* pos) -> NINDEX <

INT main () {alist.push_back (new test (15)); alist.push_back (new test (6)); alist.push_back (new test (18)); print (); alist.sort (Test_ptr_comp ()) PRINT ();

System ("pause"); Return 0;} The Sort function under the VC can only support Greater's comparison interface. Fucking ~~ The first method feels very unfriendly, and every time it takes things through Wrapper. I plan to use Sort to serve serial data. Ready to play SP6, replace the library.

转载请注明原文地址:https://www.9cbs.com/read-89851.html

New Post(0)