Re: [Cppcms-users] What did I do wrong? (tutorial #3)
Brought to you by:
artyom-beilis
|
From: Marcel H. <ke...@co...> - 2012-06-26 09:50:13
|
Am 26.06.2012 02:23, schrieb Brian Lee:
> 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'
everything you need is said here
> 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
and again here
> 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
>
and of course here ;)
>
>
> #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);
you want a reference to the method smile in the class hello, but....
(see below)
> 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>";
> }
number is declared as function only, not as method from hello, for doing
so, write
void hello:number(std::string num), but better would be
void hello:number(const std::string &num)
>
> void smile() {
> response().out() << ":) <br/>\n";
> response().out() << "<a href='" << url("/") << "'>Go back</a>";
> }
smile as number
>
> 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";
> }
the same here
>
> 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.
>
I hope this helps ;)
> Regards,
> Brian
Marcel
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>
>
> _______________________________________________
> Cppcms-users mailing list
> Cpp...@li...
> https://lists.sourceforge.net/lists/listinfo/cppcms-users
|