c++ - 包错误需要修复

标签 c++ macos makefile cmake

所以今天我想制作一个特定的包,它总是在这里“编译错误”,可以吗1 告诉我要在 fdwbackend.h 文件中修复什么?我不是 C 编码员,但我认为这不应该很难……还是?

这是来自终端的日志:

mp41:build H$ make
[  8%] Built target compat
[  8%] Building CXX object src/common/CMakeFiles/common.dir/fdwatch.o
In file included from /Users/H/Documents/gitprojects/pvpgn/src/common/fdwatch.cpp:29:
In file included from /Users/H/Documents/gitprojects/pvpgn/src/common/fdwatch_select.h:31:
/Users/H/Documents/gitprojects/pvpgn/src/common/fdwbackend.h:36:42: error: reference to type
  'const std::string'
  (aka 'const basic_string<char, char_traits<char>, allocator<char> >') could not bind to
  an lvalue of type 'const char [1]'
                    explicit InitError(const std::string& str = "")
                                                          ^     ~~
/Users/H/Documents/gitprojects/pvpgn/src/common/fdwbackend.h:36:42: note: passing argument to
  parameter 'str' here
1 error generated.
make[2]: *** [src/common/CMakeFiles/common.dir/fdwatch.o] Error 1
make[1]: *** [src/common/CMakeFiles/common.dir/all] Error 2
make: *** [all] Error 2

这里是 fdwbackend.h 代码:

#ifndef __PVPGN_FDWBACKEND_INCLUDED__
#define __PVPGN_FDWBACKEND_INCLUDED__

#include <stdexcept>

namespace pvpgn
{

class FDWBackend
{
public:
    class InitError :public std::runtime_error
    {
    public:
        explicit InitError(const std::string& str = "")
            :std::runtime_error(str) {}
        ~InitError() throw() {}
    };

    explicit FDWBackend(int nfds_);
    virtual ~FDWBackend() throw();

    virtual int add(int idx, unsigned rw) = 0;
    virtual int del(int idx) = 0;
    virtual int watch(long timeout_msecs) = 0;
    virtual void handle() = 0;

protected:
    int nfds;
};

}

#endif /* __PVPGN_FDWBACKEND_INCLUDED__ */

谢谢回复

(如果你想看完整的:https://github.com/HarpyWar/pvpgn)

最佳答案

您不能将字符串文字定义为引用的默认值。

省略引用,使用普通的按值传递

explicit InitError(const std::string str = "")
        :std::runtime_error(str) {}

关于c++ - 包错误需要修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23184048/

相关文章:

c++ - 静态变量输入时存储什么值?

macos - 在 OS X Yosemite 上构建 binutils 的交叉编译

build - 如何告诉premake生成使用clang的Makefile?

c - 生成文件问题

c++ - 你推荐什么 GNU make 替代品?

c++ - 如何使用 C++ 在 Windows 中监视进程调用

c++ - 语法 - C++ - 无法使我的代码正常工作

c++ - 添加 cout 语句可以更正输出?

macos - 如何在azure中访问我的项目的文件

node.js - 无法在 MacOSX 上安装 Appium/Node Js