Boost logo

Boost Users :

Subject: [Boost-users] Serialising templates with smart pointers....
From: Marcus MacWilliam (marcus.macwilliam_at_[hidden])
Date: 2013-08-07 10:54:42


I have the following:

_*1. An interface:*_

class IDeviceClientRequest
{
public:
    /** Empty virtual destructor. */
    virtual ~IDeviceClientRequest() {}

    /** Virtual methods to invoke on the smart pointer. */
    virtual EClientMessageIdentifier getMessageId() = 0;
}; // IDeviceClientRequest

_*2. A template class:*_

template<class Request>
class CDeviceClientRequest : public IDeviceClientRequest
{
public:
    // ...
    I have excluded the majority of the code for conciseness
    // ...

private:
    /**
     * Serialize or de-serialize the object.
     *
     * @param archive
     * When the class Archive corresponds to an output
archive, the
     * & operator is defined similar to <<. Likewise, when the
class Archive
     * is a type of input archive the & operator is defined
similar to >>.
     * @param version
     * Version identifier for backwards compatibility between
objects.
     */
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive &archive,
                   const unsigned int version)
    {
       archive & m_iMessageId
               & m_oData;
    }
}; // CDeviceClientRequest

_*3. A method to serialize from a file:*_

// Server receieves a request.
void devices::comms::CDeviceCommunication::receiveRequest(
std::unique_ptr<devices::request::IDeviceClientRequest>& request)
{
    // Open the file for read.
    std::ifstream file(getFilename().c_str());

    // Use boost to serialize the object from the file.
    boost::archive::binary_iarchive archive(file);
    archive >> *request;

    // Close the file.
    file.close();
}

What do I need to add to the interface class to stop the following
compile error:

error C2039: 'serialize' : is not a member of
'devices::request::IDeviceClientRequest'

Thanks,

-- 
Marcus A.T MacWilliam, Senior Software Engineer. 1Spatial Ltd.
Tel: +44 (0)1223 420414, ext 2289,    Mob: +44 (0)7803 706597.
E-Mail: marcus.macwilliam_at_[hidden] Skype:marcus.macwilliam
Tennyson House, 7 Cambridge Business Park, Cambridge, CB4 0WZ.
Registered in England No. 4785688,     VAT Reg. No. 135539408.
Website: http://www.1spatial.com/    E-mail: info_at_[hidden]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net