CppCMS构建构造函数&宣言

时间:2013-04-04 01:44:14

标签: c++ cppcms

来自http://cppcms.com/wikipp/en/page/cppcms_1x_forms

根据this

  

声明将一个或多个名称引入程序.....   因此,类,结构,枚举类型等   可以为每个编译单元声明用户定义的类型

AFAIK,构造函数应该在myapp.cpp,而声明应该在content.h。所以我把

表单上有5个字段。在CppCMS中,使用3个代码构建的表单(第4个代码是对字段的限制)

第一个代码:

name.message("Your Name");
sex.message("Sex");
marital.message("Marital Status");
age.message("Your Age");
submit.value("Send");

第二个代码:

add(name);
add(sex);
add(marital);
add(age);
add(submit);

第3段代码:

sex.add("Male","male");
sex.add("Female","female");
marital.add("Single","single");
marital.add("Married","married");
marital.add("Divorced","divorced");

第4个代码,是对字段的限制:

name.non_empty();
age.range(0,120);

我很困惑哪一个应该是宣言

------------------加

我已尝试在myapp.cpp中添加以上所有代码,如下所示:

class myapp : public cppcms::application {
public:
    myapp(cppcms::service &srv) : cppcms::application(srv)
    {
        dispatcher().assign("",&myapp::info_form,this);
        mapper().assign("");
    }
    void info_form()
    {
        name.message("Your Name");
        sex.message("Sex");
        marital.message("Marital Status");
        age.message("Your Age");
        submit.value("Send");

        add(name);
        add(sex);
        add(marital);
        add(age);
        add(submit);

        sex.add("Male","male");
        sex.add("Female","female");
        marital.add("Single","single");
        marital.add("Married","married");
        marital.add("Divorced","divorced");

        name.non_empty();
        age.range(0,120);
    }
};

但它仍然给出错误:

myapp.cpp: In member function ‘void myapp::info_form()’:
myapp.cpp:20:9: error: ‘name’ was not declared in this scope
myapp.cpp:21:9: error: ‘sex’ was not declared in this scope
myapp.cpp:22:9: error: ‘marital’ was not declared in this scope
myapp.cpp:23:9: error: ‘age’ was not declared in this scope
myapp.cpp:24:9: error: ‘submit’ was not declared in this scope
myapp.cpp:24:9: note: suggested alternative:
/usr/local/include/cppcms/form.h:1574:20: note:   ‘cppcms::widgets::submit’
myapp.cpp: At global scope:
myapp.cpp:43:37: error: no ‘void myapp::main(std::string)’ member function declared in class ‘myapp’
my_skin.tmpl:4:2: error: expected unqualified-id before ‘if’
my_skin.tmpl:8:3: error: expected unqualified-id before ‘else’
my_skin.tmpl:12:8: error: expected constructor, destructor, or type conversion before ‘<<’ token
my_skin.tmpl:13:2: error: expected unqualified-id before ‘{’ token

0 个答案:

没有答案
相关问题