在"结构提升::enable_if<提升::is_pod<T>,无效>"中没有名为"type"的类型

no type named ‘type’ in ‘struct boost::enable_if<boost::is_pod<T>, void>’

本文关键字:gt lt 无效 类型 type is 结构 enable if pod 提升      更新时间:2023-10-16

我正在尝试在Linux中编译此存储库,但是在此步骤中遇到了一些麻烦。

*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);

*序列化/元素BS

.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::d isable_if<boost::is_pod>, void>::type bil::writeBinary(const std::vector&, std::ostream&( [with T = std::__cxx11::

basic_string; typename boost::d isable_if<boost::is_pod>, void>::type = void; std::ostream = std::basic_ostream]':
serialization/ElementBS.cpp:16:45:从这里需要
util/BinarySerialization.hpp:78:21: 错误:调用 'writeBinary(const value_type&, std::ostream&('
writeBinary(data[i], outputStream(;          
...
二进制序列化.hpp:31:5:错误:结构提升::enable_if<提升::is_pod><std::__cxx11::basic_string><字符>>,无效>"中没有名为"类型"的类型

ElementBS中的第一个writeBinary.cpp与BinarySerialization.hpp中的最后一个函数匹配,ElementBS中的第二个函数.cpp与第三个函数匹配。但是,writeBinary(data[i], outputStream(;在第三个函数中无法匹配任何函数。我不知道如何解决它;

若要修复编译器错误,请确保声明void writeBinary(const std::string& data, std::ostream& outputStream);位于函数模板writeBinary之前。

这是因为在模板实例化期间,将执行依赖名称查找的第二阶段,仅执行依赖于参数的名称查找。由于要writeBinary(const std::string& data, std::ostream& outputStream)的参数来自命名空间std因此依赖于参数的名称查找永远不会找到此重载,因为它不在命名空间std中。

通过在使用该函数的函数模板之前声明该函数,可以使该函数在两阶段查找的第一阶段可用。然后在函数模板实例化(名称查找的第二阶段(期间考虑此名称。