Procházet zdrojové kódy

Fix use of std::vector in optional C++ interface (see #262)

bel před 9 roky
rodič
revize
58ca276782
2 změnil soubory, kde provedl 9 přidání a 3 odebrání
  1. 7 2
      examples/embedded_cpp/embedded_cpp.cpp
  2. 2 1
      src/CivetServer.cpp

+ 7 - 2
examples/embedded_cpp/embedded_cpp.cpp

@@ -251,11 +251,16 @@ class FooHandler : public CivetHandler
 int
 main(int argc, char *argv[])
 {
-
 	const char *options[] = {
 	    "document_root", DOCUMENT_ROOT, "listening_ports", PORT, 0};
+    
+    std::vector<std::string> cpp_options;
+    for (int i=0; i<(sizeof(options)/sizeof(options[0])-1); i++) {
+        cpp_options.push_back(options[i]);
+    }
 
-	CivetServer server(options);
+	// CivetServer server(options); // <-- C style start
+    CivetServer server(cpp_options); // <-- C++ style start
 
 	ExampleHandler h_ex;
 	server.addHandler(EXAMPLE_URI, h_ex);

+ 2 - 1
src/CivetServer.cpp

@@ -282,6 +282,7 @@ CivetServer::CivetServer(const char **options,
 		throw CivetException("null context when constructing CivetServer. "
 		                     "Possible problem binding to port.");
 }
+
 CivetServer::CivetServer(std::vector<std::string> options,
                          const struct mg_callbacks *_callbacks)
     : context(0)
@@ -299,7 +300,7 @@ CivetServer::CivetServer(std::vector<std::string> options,
 
 	std::vector<const char *> pointers(options.size());
 	for (size_t i = 0; i < options.size(); i++) {
-		pointers.push_back(options[i].c_str());
+		pointers[i] = (options[i].c_str());
 	}
 	pointers.push_back(0);