当前位置: 首页 > 知识库问答 >
问题:

在“struct boost::enable_if”中没有名为'type'的类型

沃楷
2023-03-14

我正在尝试在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'的实例化中

ElementB中的第一个writeBinary。cpp与二进制序列化中的最后一个函数匹配。hpp和ElementBS中的第二个函数。cpp与第三个函数匹配。但是,writeBinary(数据[i],输出流);第三个函数无法匹配任何函数。我不知道如何修复它;

共有1个答案

温源
2023-03-14

要修复编译器错误,请确保声明 void writeBinary(const std::string

这是因为在模板实例化期间,仅执行依赖名称查找的第二阶段,仅执行与参数相关的名称查找。自写参数二进制(const std::string)以来

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

 类似资料:
  • 我使用这个神奇的标题来获得轻松序列化STL容器的能力。 然而,我现在已经开始为我的类型使用更高级的HTML序列化程序,我想做的部分工作是泛化

  • 我正在学习如何获取重载函数vs的返回值的。 我修改了SO答案中的代码(由chris编写)。 我有一个编译错误。 错误:“std::result\u of”中没有名为“type”的类型 据我所知:- >

  • 我的数据库中有一个实体的表。此表包含一些类型为的列(这是一个要求,我不能更改它),但Hibernate不使用注释,就无法将此列类型映射到我的中的正确属性,它抱怨它希望得到一个类型为的列,而不是的列: 是否有任何方法可以配置hibernate,使其能够映射到类型,而不使用符合JPA规范的注释? Spring启动版本: Hibernate版本: Hibernate方言:

  • 我在PyCharm中有一个Python代码,我在其中使用导入请求,但终端显示以下错误: (venv)ahmad@Ahmad:~/Desktop/spider$python测试。py回溯(最近一次调用last):导入请求模块中第1行的文件“test.py”NotFoundError:没有名为“requests”的模块 但我也安装了pip和请求。

  • 以下是我在尝试从flask_sqlalchemy import sqlalchemy在python3中运行以下代码时遇到的主要错误 不确定它是否相关,但当我更新sqlaclhemy时,它给出了以下pip提示。我尝试过更新pip,但由于某些原因,9.0.1版说它已升级,但实际上没有更新。 下面是我运行pip列表时得到的结果,您可以看到sqlalchemy和flask sqlalchemy都已安装。

  • 我对python和pycharm很陌生 我通过anaconda安装了python 3.6,我可以看到包括numpy在内的许多软件包都已安装,因为我可以通过键入“conda list”在cmd(im using windows)中看到它们。此外,如果我通过窗口命令提示符在python中键入“import numpy”,它也会起作用。 但是,如果我打开pycharm并在那里运行“import nump