Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何序列化模板类_C++_Templates_Serialization - Fatal编程技术网

C++ 如何序列化模板类

C++ 如何序列化模板类,c++,templates,serialization,C++,Templates,Serialization,我正在对遗留代码执行一些后台维护 它包括用STL和boost替换不推荐使用的库,同时尽可能保持界面的相似性 ostream& operator<<(ostream& vos, const OurList<class T>& coll) { // OurList wraps an stl list with the same interface as the current library // OurListIterator wra

我正在对遗留代码执行一些后台维护

它包括用STL和boost替换不推荐使用的库,同时尽可能保持界面的相似性

ostream& operator<<(ostream& vos, const OurList<class T>& coll)
{
    // OurList wraps an stl list with the same interface as the current library
    // OurListIterator wraps an iterator class used to access OurList

    OurListIterator<T, OurList<class T> > iter((OurList<class T>&)coll);

    // this function gets the first item in the list and then each next one
    while (iter())
    {
        // key returns the value pointed to by the iterator
        vos << iter.key();
    }
};
然而,当我编译它时,我在vos上得到一个错误您可以尝试:添加模板,删除类

尝试删除类。这还取决于T的类型。如果不为其重载运算符,T可能无法插入。
template <typename T>
ostream& operator<<(ostream& vos, const OurList<T>& coll)
{
    // OurList wraps an stl list with the same interface as the current library
    // OurListIterator wraps an iterator class used to access OurList

    OurListIterator<T, OurList<T> > iter((OurList<T>&)coll);

    // this function gets the first item in the list and then each next one
    while (iter())
    {
        // key returns the value pointed to by the iterator
        vos << iter.key();
    }
}