[Assorted-commits] SF.net SVN: assorted:[902] sandbox/trunk/src/cc/sort.cc
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-07-21 16:12:10
|
Revision: 902 http://assorted.svn.sourceforge.net/assorted/?rev=902&view=rev Author: yangzhang Date: 2008-07-21 16:12:13 +0000 (Mon, 21 Jul 2008) Log Message: ----------- added sort.cc Added Paths: ----------- sandbox/trunk/src/cc/sort.cc Added: sandbox/trunk/src/cc/sort.cc =================================================================== --- sandbox/trunk/src/cc/sort.cc (rev 0) +++ sandbox/trunk/src/cc/sort.cc 2008-07-21 16:12:13 UTC (rev 902) @@ -0,0 +1,30 @@ +#include <algorithm> +#include <vector> +using namespace std; + +class cmp { + public: bool operator()(int a, int b) const { return a < b; } +} cmp; + +int +main() +{ + vector<int> xs; + + // This doesn't work. From + // + // http://www.gamedev.net/community/forums/topic.asp?topic_id=390922&whichpage=1� + // + // "I thought you could declare classes local to functions, but apparently + // not. I moved it to the global scope and it works fine. Thanks guys." + // + // "You can to some extent, but they will have internal linkage. Template + // parameters must have external linkage, which rules out local types." + // + // class cmp { + // public: bool operator()(int a, int b) const { return a < b; } + // } cmp; + + sort(xs.begin(), xs.end(), cmp); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |