【发布时间】:2018-10-09 10:48:57
【问题描述】:
我正在尝试在 Linux 中编译这个 repo,但是这一步遇到了一些麻烦。
*util/BinarySerialization.hpp
template <typename T> inline
typename boost::enable_if<boost::is_pod<T>, void>::type
writeBinary(const T& data, std::ostream& outputStream)
{
...
}
template <typename T> inline
typename boost::enable_if<boost::is_pod<T>, void>::type
writeBinary(const std::vector<T>& data, std::ostream& outputStream)
{
...
}
template <typename T> inline
typename boost::disable_if<boost::is_pod<T>, void>::type
writeBinary(const std::vector<T>& data, std::ostream& outputStream)
{
// write vector length
size_t length = data.size();
outputStream.write(reinterpret_cast<const char*>(&length), sizeof(length));
if (!outputStream) throw IOException();
// write vector data one by one
for (size_t i = 0; i < length; ++i)
writeBinary(data[i], outputStream); // error!
}
void writeBinary(const std::string& data, std::ostream& outputStream);
*序列化/ElementBS.cpp
void bil::writeBinary(const Element& data, std::ostream& outputStream)
{
writeBinary(data.m_name, outputStream);
writeBinary(data.m_options, outputStream);
}
*xdlrc/model/Element.hpp
typedef std::vector<std::string> ConfigurationOptions;
class Element {
public:
Element();
std::string& name();
const std::string& name() const;
ConfigurationOptions& options();
const ConfigurationOptions& options() const;
void clear();
private:
friend void writeBinary(const Element& data, std::ostream& outputStream);
friend void readBinary(Element& data, std::istream& inputStream);
std::string m_name;
ConfigurationOptions m_options;
};
util/BinarySerialization.hpp: 在 'typename boost::disable_if<:is_pod>, void >::type bil::writeBinary(const std::vector
&, std:: ostream&) [with T = std::__cxx11::basic_string ;类型名 boost::disable_if<:is_pod>, void>::type = void; std::ostream = std::basic_ostream ]':
序列化/ElementBS.cpp:16:45:从这里需要
util/BinarySerialization.hpp:78:21: 错误: 没有匹配函数调用'writeBinary(const value_type&, std::ostream&)'
writeBinary(data[i], outputStream);
...
BinarySerialization.hpp:31:5: 错误: 'struct boost::enable_if<:is_pod>>, void>'中没有名为'type'的类型
ElementBS.cpp 中的第一个 writeBinary 与 BinarySerialization.hpp 中的最后一个函数匹配,ElementBS.cpp 中的第二个函数与第三个函数匹配。但是, writeBinary(data[i], outputStream);在第三个功能无法匹配任何功能。我不知道如何解决它;
【问题讨论】:
-
void writeBinary(const std::string& data, std::ostream& outputStream);我只在这里看到了声明。函数定义在哪里? -
函数定义在util/BinarySerialization.cpp中。