我需要std::map按值而不是按键排序.有一个简单的方法吗?
我从下面的线程中得到了一个解决方案:
std :: map按数据排序?
有更好的解决方案吗?
map<long, double> testMap;
// some code to generate the values in the map.
sort(testMap.begin(), testMap.end()); // is there any function like this to sort the map?
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个将对象转换为JaxbRepresentation的示例测试应用程序.但是当我试图运行它时,它给了我一个错误.
Main.java文件
package test_jaxb;
import org.restlet.Server;
import org.restlet.data.Protocol;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
Server helloServer = new Server(Protocol.HTTP, 8111,
TestResource.class);
helloServer.start();
}
}
Run Code Online (Sandbox Code Playgroud)
TestResource.java文件
package test_jaxb;
import org.restlet.ext.jaxb.JaxbRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;
public class TestResource extends ServerResource{
@Override
protected Representation get() throws ResourceException {
SampleResponse res = new SampleResponse();
res.setMsg("Success");
res.setStatusCode(0);
JaxbRepresentation<SampleResponse> representation = new JaxbRepresentation<SampleResponse>(res);
return representation;
}
}
Run Code Online (Sandbox Code Playgroud)
SampleResponse.java文件
package …Run Code Online (Sandbox Code Playgroud) 可能重复:
FAQ:如何将对象传递给C++中的函数?
指针与参考
大家好,
在c/c ++中,我们可以通过引用传递对象或传递对象的指针.
例如:
我想创建一个函数,它将字符串向量作为输入,并输出一个包含每个字符串的值的映射.函数的返回值是bool,表示成功或失败.
功能(按参考调用)
bool calculateSomeValue( vector<string> input, map<string, double>& result)
{
//// bla bla bla
return true/false;
}
功能(使用指针)
bool calculateSomeValue( vector<string> input, map<string, double>* result)
{
//// bla bla bla
return true/false;
}
哪一个最好?有没有人知道这两种选择的利弊?
提前致谢.