CppCMS教程:静态链接模板错误(控制器问题)
CppCMS tutorial: Linking template statically error (controller issue)
From http://cppcms.com/wikipp/en/page/cppcms_1x_tut_hello_templates#The.controller
我在hello.cpp
的底部放置了以下代码:
virtual void main(std::string /*url*/)
{
content::message c;
c.text=">>>Hello<<<";
render("message",c);
}
运行g++ hello.cpp my_skin.cpp -o hello -lcppcms -lbooster
时,得到错误:
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
我错过了什么吗
错误信息告诉了你需要知道的一切。
-
virtual
只能在一个类中使用。你的主方法不在类中。 -
main
方法必须返回int
。您的返回void
。 - 有两个主要方法,一个是
main(std::string)
,另一个是main(int, char**)
- 你的渲染方法必须在主方法上面有一个函数原型,否则整个方法需要移动。
所以这样更合适:
void render(std::string, std::string) // or whatever
{
// do something
}
int main(int argc, char** argv)
{
render("string", c);
return 0;
}
您的hello.cpp应该如下所示:
#include <cppcms/application.h>
#include <cppcms/applications_pool.h>
#include <cppcms/service.h>
#include <cppcms/http_response.h>
#include <iostream>
#include "content.h"
class hello : public cppcms::application {
public:
hello(cppcms::service &srv) : cppcms::application(srv) {}
virtual void main(std::string url);
};
void hello::main(std::string /*url*/){
content::message cc;
cc.text=">>>Hello<<<";
render("message", cc);
}
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;
}
}
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- 哗啦��错误:无法识别任何一组可以驱动指定关节的控制器
- Irrlicht Collada 加载程序警告:发现错误的标记用法:库控制器
- CppCMS教程:静态链接模板错误(控制器问题)
- xbox 360 控制器功能的链接器错误