Re: [Cppcms-users] What did I do wrong? (tutorial #3)
Brought to you by:
artyom-beilis
From: kpeo <sla...@ya...> - 2012-06-26 06:55:56
|
Hello, You use functions as &hello::number in dispatcher, but not declare it inside class. So declare it below "main": class hello ... { ... virtual void main(std::string url); void number(std::string); void smile(); void welcome(); }; and write it below as "hello::number", etc. instead "number": void hello::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>"; } > 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): ... > 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 |