पर कॉल नहीं करता है, मैंने समान प्रश्नों के लोड के माध्यम से पढ़ा है लेकिन उत्तर नहीं मिला है। मैं विजुअल स्टूडियो 2010 का उपयोग कर रहा हूं और 1.47 बढ़ा सकता हूं।व्युत्पन्न ऑब्जेक्ट का बूस्ट क्रमबद्धता व्युत्पन्न के serialize()
यहाँ कोड है, यह पूर्ण और compilable है:
#include "stdafx.h"
#include <string>
#include <sstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/export.hpp>
using namespace std;
class BaseObject
{
public:
BaseObject(void) { };
virtual ~BaseObject(void) { };
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{ /* nothing happens here */ };
};
class DerivedObject : public BaseObject
{
public:
string text;
public:
DerivedObject(void) { };
~DerivedObject(void) { };
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & text;
};
};
BOOST_CLASS_EXPORT(DerivedObject)
int _tmain(int argc, _TCHAR* argv[])
{
DerivedObject der;
der.text = "Testing!";
std::ostringstream os;
boost::archive::text_oarchive oa(os);
oa.register_type<DerivedObject>();
// I made a DerivedObject, but I'm casting it to a BaseObject
// as the serialization code should not have to know what type it is
BaseObject *base = &der;
// now serialize it
oa << *base;
printf("serialized: %s\r\n",os.str().c_str());
return (0);
}
आप यह असली आसान है देख सकते हैं, और मैं BOOST_CLASS_EXPORT और oa.register_type जादू है कि यकीन है कि DerivdObject :: serialize करना चाहिए था जोड़ दिया है() हालांकि यह वर्चुअल विधि नहीं है .. लेकिन अभी भी बेसऑब्जेक्ट में केवल serialize() कहा जाता है। शायद दृश्य सी ++ के लिए विशिष्ट समस्या? कृपया सलाह दें?
क्या आपके 'बेसऑब्जेक्ट :: धारावाहिक' को 'आभासी' के रूप में चिह्नित नहीं किया जाना चाहिए? – Nick
नहीं यह एक टेम्पलेट है, यह टी –
अच्छा बिंदु - टेम्पलेट बिट नोटिस नहीं किया! – Nick