http://cppcms.com/wikipp/en/page/cppcms_1x_formsから、
これによると、
宣言は、1 つまたは複数の名前をプログラムに導入します。したがって、クラス、構造体、列挙型、およびその他のユーザー定義型を、コンパイル単位ごとに宣言できます。
私の知る限り、コンストラクターは にあるはずですが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");
2 番目のコード:
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