[Cppcms-users] What did I do wrong? (tutorial #3)
Brought to you by:
artyom-beilis
From: Brian L. <to...@gm...> - 2012-06-26 00:23:49
|
Hey everyone, I just installed CppCMS on Windows with a MinGW shell. I'm still pretty new to C++ and am setting up a web server as a learning exercise, but I'm stuck at tutorial 3. I pretty much copy-pasted all the code -- did I go wrong, or is there something wrong with my environment? I'm getting compile errors using g++ (g++ hello.cpp -lcppcms -o hello): hello.cpp: In constructor, 'hello::hello(cppcms::service&)': hello.cpp:14:43: error 'number' is not a member of 'hello' hello.cpp:17:35: error: 'smile' is not a member of 'hello' hello.cpp:20:29: error: 'welcome' is not a member of 'hello' hello.cpp: In function 'void number(std::string)': hello.cpp:39:11: error: 'response' was not declared in this scope hello.cpp:40:44: error: 'url' was not declared in this scope hello.cpp: In function 'void smile()': hello.cpp:44:11: error: 'response' was not declared in this scope hello.cpp:45:44: error: 'url' was not declared in this scope hello.cpp:49:11: error: 'response' was not declared in this scope hello.cpp:51:33: error: 'url' was not declared in this scope #include <cppcms/application.h> #include <cppcms/service.h> #include <cppcms/http_response.h> #include <cppcms/url_dispatcher.h> #include <cppcms/url_mapper.h> #include <cppcms/applications_pool.h> #include <iostream> #include <stdlib.h> class hello : public cppcms::application { public: hello(cppcms::service &srv) : cppcms::application(srv) { dispatcher().assign("/number/(\\d+)",&hello::number,this,1); mapper().assign("number","/number/{1}"); dispatcher().assign("/smile",&hello::smile,this); mapper().assign("smile","/smile"); dispatcher().assign("",&hello::welcome,this); mapper().assign(""); mapper().root("/hello"); } virtual void main(std::string url); }; void hello::main(std::string url) { response().out() << "<html>\n" "<body>\n" " <h1>Hello, world!</h1>\n" "</body>\n" "</html>\n"; } void number(std::string num) { int no = atoi(num.c_str()); response().out() << "The number is " << no << "<br/>\n"; response().out() << "<a href='" << url("/") << "'>Go back</a>"; } void smile() { response().out() << ":) <br/>\n"; response().out() << "<a href='" << url("/") << "'>Go back</a>"; } void welcome() { response().out() << "<h1> Wellcome To Page with links </h1>\n" "<a href='" << url("/number",1) << "'>1</a><br>\n" "<a href='" << url("/number",15) << "'>15</a><br>\n" "<a href='" << url("/smile") << "' >:)</a><br>\n"; } int main(int argc, char ** argv) { try { cppcms::service srv(argc, argv); srv.applications_pool().mount ( cppcms::applications_factory<hello>() ); srv.run(); } catch(std::exception const&e) { std::cerr << e.what() << std::endl; } } Any help would be much appreciated. Regards, Brian |