Re: [Cppcms-users] Compile error: traits is not a template
Brought to you by:
artyom-beilis
From: 陈抒 <csf...@gm...> - 2012-09-01 07:07:19
|
json.h was added into group.h groups.h include group.h 陈抒 Best regards http://blog.csdn.net/sheismylife On Sat, Sep 1, 2012 at 3:05 PM, 陈抒 <csf...@gm...> wrote: > Thank you. But I see new error. > groups.h file: > > #ifndef __GROUPS_H > #define __GROUPS_H > > #include <vector> > #include <boost/shared_ptr.hpp> > #include "group.h" > > namespace kaimei{ > > class groups{ > public: > typedef std::vector<boost::shared_ptr<group> >::iterator iterator; > typedef std::vector<boost::shared_ptr<group> >::const_iterator > const_iterator; > > void add(boost::shared_ptr<group> g); > > bool empty() const; > > unsigned int size() const; > > std::string json_string() const; > > friend class cppcms::json::traits<kaimei::groups>; > > private: > std::vector<boost::shared_ptr<kaimei::group> > values_; > }; > > } > > namespace cppcms { > namespace json { > > template<> > struct traits<kaimei::groups> { > > static void set(value &v, kaimei::groups const& in) { > v.set("size", in.size()); > v.set("values", in.values_); > } > }; > > } > } > > #endif > > > error message: > 3%] Generating ../../src/view/welcome.cpp, ../../src/view/home.cpp, > ../../src/view/gprs_message.cpp, ../../src/view/gprs_manager.cpp, > ../../src/view/gprs_password.cpp, ../../src/view/gprs_log.cpp, > ../../src/view/register_client.cpp, ../../src/view/gprsConfig.cpp, > ../../src/view/login.cpp, ../../src/view/group_management.cpp > [ 6%] Building CXX object bin/CMakeFiles/cppweb.dir/groups.cpp.o > In file included from /home/chenshu/work/kaimei/cppweb/include/group.h:5:0, > from /home/chenshu/work/kaimei/cppweb/include/groups.h:6, > from /home/chenshu/work/kaimei/cppweb/src/groups.cpp:1: > /usr/include/cppcms/json.h: In member function ‘void > cppcms::json::value::set_value(const T&) [with T = > boost::shared_ptr<kaimei::group>]’: > /usr/include/cppcms/json.h:604:5: instantiated from ‘static void > cppcms::json::traits<std::vector<T> >::set(cppcms::json::value&, const > std::vector<T>&) [with T = boost::shared_ptr<kaimei::group>]’ > /usr/include/cppcms/json.h:247:4: instantiated from ‘void > cppcms::json::value::set_value(const T&) [with T = > std::vector<boost::shared_ptr<kaimei::group> >]’ > /usr/include/cppcms/json.h:316:4: instantiated from > ‘cppcms::json::value::value(const T&) [with T = > std::vector<boost::shared_ptr<kaimei::group> >]’ > /usr/include/cppcms/json.h:352:4: instantiated from ‘void > cppcms::json::value::set(const char*, const T&) [with T = > std::vector<boost::shared_ptr<kaimei::group> >]’ > /home/chenshu/work/kaimei/cppweb/include/groups.h:39:28: instantiated > from here > /usr/include/cppcms/json.h:247:4: error: incomplete type > ‘cppcms::json::traits<boost::shared_ptr<kaimei::group> >’ used in nested > name specifier > make[2]: *** [bin/CMakeFiles/cppweb.dir/groups.cpp.o] Error 1 > make[1]: *** [bin/CMakeFiles/cppweb.dir/all] Error 2 > make: *** [all] Error 2 > > > 陈抒 > Best regards > http://blog.csdn.net/sheismylife > > > On Sat, Sep 1, 2012 at 2:34 PM, Artyom Beilis <art...@ya...> wrote: > >> > >> >> >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{ >> >... >> } >> > >> > >> >namespace cppcms { >> > namespace json { >> > template<> >> > struct traits<kaimei::group> { >> >... >> > } >> > } >> >} >> > >> > >> > >> > [snip] >> > >> >I am not good at template programming. Why did this happen? >> > >> >> You can't specialize undefined struct - you need to include >> <cppcms/json.h> >> header. It provides the original traits struct and than you specialize it >> for >> your type of class >> >> >> > >> >陈抒 >> >Best regards >> >http://blog.csdn.net/sheismylife >> > >> >> Regards, >> Artyom >> >> >> >> ------------------------------------------------------------------------------ >> Live Security Virtual Conference >> Exclusive live event will cover all the ways today's security and >> threat landscape has changed and how IT managers can respond. Discussions >> will include endpoint security, mobile security and the latest in malware >> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users >> > > |