[Cppcms-users] Compile error: traits is not a template
Brought to you by:
artyom-beilis
|
From: 陈抒 <csf...@gm...> - 2012-08-31 15:37:14
|
I have a correct class with no compilation error. All codes in response.h:
#ifndef __RESPONSE_H
#define __RESPONSE_H
namespace kaimei{
class response {
public:
enum
{OK=0,SAVE_EMAIL_ERROR=1,CHANGE_PWD_ERROR=2,LOGIN_ERROR=3,CREATE_ACCOUNT_ERROR=4,
SAVE_MESSAGE_ERROR=5,CHANGE_LANGUAGE_ERROR=6,NONE_CONTENT=7,LOAD_DISPLAY_ERROR=8,
NONE_USER_ID=9,GET_MESSAGE_LOG_ERROR=10,QUIT_ERROR=11,NONE_ADMIN=12,BIND_ERROR=13,
UPDATE_DESCRIPTION_ERROR=14,UNBIND_ERROR=15,LOAD_GROUPS_ERROR=16,UPDATE_GROUP_NAME_ERROR=17
};
int status;
string message;
string value;
};
}
namespace cppcms {
namespace json {
template<>
struct traits<kaimei::response> {
static void set(value &v, kaimei::response const& in) {
v.set("status", in.status);
v.set("message", in.message);
v.set("value", in.value);
}
};
}
}
#endif
But I got error when compiling another class. It has group.h and group.cpp
file.
#ifndef __GROUP_H
#define __GROUP_H
#include <string>
namespace kaimei{
class group {
public:
group();
std::string id;
std::string description;
std::string name;
int device_number;
std::string json_string() const;
};
}
namespace cppcms {
namespace json {
template<>
struct traits<kaimei::group> {
static void set(value &v, kaimei::group const& in) {
v.set("id", in.id);
v.set("description", in.description);
v.set("name", in.name);
v.set("deviceNumber", in.device_number);
}
};
}
}
#endif
Error output:
[ 3%] Building CXX object bin/CMakeFiles/cppweb.dir/groups.cpp.o
In file included from /home/chenshu/work/kaimei/cppweb/include/groups.h:6:0,
from /home/chenshu/work/kaimei/cppweb/src/groups.cpp:1:
/home/chenshu/work/kaimei/cppweb/include/group.h:24:14: error: ‘traits’ is
not a template
/home/chenshu/work/kaimei/cppweb/include/group.h:24:36: error: explicit
specialization of non-template ‘cppcms::json::traits’
/home/chenshu/work/kaimei/cppweb/include/group.h:26:23: error: ‘value’ has
not been declared
/home/chenshu/work/kaimei/cppweb/include/group.h: In static member function
‘static void cppcms::json::traits::set(int&, const kaimei::group&)’:
/home/chenshu/work/kaimei/cppweb/include/group.h:27:4: error: request for
member ‘set’ in ‘v’, which is of non-class type ‘int’
/home/chenshu/work/kaimei/cppweb/include/group.h:28:4: error: request for
member ‘set’ in ‘v’, which is of non-class type ‘int’
/home/chenshu/work/kaimei/cppweb/include/group.h:29:4: error: request for
member ‘set’ in ‘v’, which is of non-class type ‘int’
/home/chenshu/work/kaimei/cppweb/include/group.h:30:4: error: request for
member ‘set’ in ‘v’, which is of non-class type ‘int’
I am not good at template programming. Why did this happen?
陈抒
Best regards
http://blog.csdn.net/sheismylife
|