From http://cppcms.com/wikipp/en/page/cppcms_1x_tut_hello_templates#The.controller
I've places below codes on bottom of hello.cpp
:
virtual void main(std::string /*url*/)
{
content::message c;
c.text=">>>Hello<<<";
render("message",c);
}
When running g++ hello.cpp my_skin.cpp -o hello -lcppcms -lbooster
, got error:
hello.cpp:44:38: error: ‘virtual’ outside class declaration
hello.cpp:44:38: error: ‘::main’ must return ‘int’
hello.cpp:44:14: warning: first argument of ‘int main(std::string)’ should be ‘int’ [-Wmain]
hello.cpp:44:14: warning: ‘int main(std::string)’ takes only zero or two arguments [-Wmain]
hello.cpp: In function ‘int main(std::string)’:
hello.cpp:44:38: error: declaration of C function ‘int main(std::string)’ conflicts with
hello.cpp:27:5: error: previous declaration ‘int main(int, char**)’ here
hello.cpp: In function ‘int main(std::string)’:
hello.cpp:48:23: error: ‘render’ was not declared in this scope
Do I missed something
The error messages are telling you everything you need to know.
virtual
can only be used in a class. Your main method is not in a class.main
method must return an int
. Yours is returning void
.main(std::string)
and one that is main(int, char**)
So this would be more appropriate:
void render(std::string, std::string) // or whatever
{
// do something
}
int main(int argc, char** argv)
{
render("string", c);
return 0;
}