C++ CppCMS构建构造器&;宣言

C++ CppCMS构建构造器&;宣言,c++,cppcms,C++,Cppcms,从 根据, 声明将一个或多个名称引入程序。。。。。 因此,类、结构、枚举类型和其他 可以为每个编译单元声明用户定义的类型 好的,构造函数应该在myapp.cpp中,而声明应该在content.h中。所以我把 表单上有5个字段。在CppCMS中,使用3个代码构建的表单(第4个代码是对字段的限制) 第1代码: name.message("Your Name"); sex.message("Sex"); marital.message("Marital Status"); age.message("Y

根据,

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

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

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

第1代码:

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
中添加上述所有代码,如下所示:

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
myapp.cpp:在成员函数“void myapp::info_form()”中:
myapp.cpp:20:9:错误:“名称”未在此作用域中声明
myapp.cpp:21:9:错误:未在此作用域中声明“sex”
myapp.cpp:22:9:错误:未在此作用域中声明“婚姻”
myapp.cpp:23:9:错误:未在此作用域中声明“年龄”
myapp.cpp:24:9:错误:未在此作用域中声明“提交”
myapp.cpp:24:9:注:建议的备选方案:
/usr/local/include/cppcms/form.h:1574:20:注意:'cppcms::widgets::submit'
myapp.cpp:在全局范围内:
myapp.cpp:43:37:错误:在类“myapp”中未声明“void myapp::main(std::string)”成员函数
my_skin.tmpl:4:2:错误:在“if”之前应为非限定id
my_skin.tmpl:8:3:错误:在'else'之前应为非限定id

my_skin.tmpl:12:8:错误:在“这些都不是声明”之前需要构造函数、析构函数或类型转换。这些都是被调用的函数。声明什么是
姓名
性别
婚姻
的代码是。。。这些都是声明。我已经尝试将以上所有代码放入
myapp.cpp
,但它说它需要声明。您以前声明过变量吗?如果您没有,这可能是一个太复杂的程序,您现在无法执行。如果有,您能回答关于您的第一个错误的问题吗?什么是
名称
?它是一个
std::string
?一个
int
?@Drew Dorman,
name
std::string
我个人不知道
name
应该是什么,但我知道它不是
std::string
。我在代码中看到
name.message
name.non_empty
,并且
std::string
没有定义这些函数。我可以告诉你这么多:你的第一个错误是编译器也不知道
名称是什么。这段代码似乎缺失了很多部分。