用公共访问编译器错误重新声明了sstream [英] sstream redeclared with public access compiler error

查看:623
本文介绍了用公共访问编译器错误重新声明了sstream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用gcc5.4.0在大型项目上运行make时,我遇到了此错误.

I came across this error when running make on a large project using gcc5.4.0.

/usr/include/c++/5/sstream:300:14: error: '__xfer_bufptrs' redeclared with 'public' access
      struct __xfer_bufptrs
             ^
/usr/include/c++/5/sstream:67:14: note: previously declared 'private' here
      struct __xfer_bufptrs;

在我看来,编译器似乎有问题?由于问题出现在标准的c ++库sstream中?这对我来说没有意义,我使用的是错误的编译器吗?

To me it seems like an issue with the compiler? Since the issue arises in a standard c++ library sstream? It does not make sense to me, am I using a wrong compiler?

以下是错误消息所引用的代码段:

Here are the code snippets the error messages refer to:

1.)sstream从第67行开始

1.) sstream starting at line 67

class basic_stringbuf : public basic_streambuf<_CharT, _Traits>                                   
    {                                                                                                 
      struct __xfer_bufptrs;                                                                          
    public:                                                                                           

2.)在第300行上同步播放

2.) sstream at line 300

#if _GLIBCXX_USE_CXX11_ABI                                                                            
      // This type captures the state of the gptr / pptr pointers as offsets                          
      // so they can be restored in another object after moving the string.                           
      struct __xfer_bufptrs                                                                           
      {                                                                                               
        __xfer_bufptrs(const basic_stringbuf& __from, basic_stringbuf* __to)                          
        : _M_to{__to}, _M_goff{-1, -1, -1}, _M_poff{-1, -1, -1}                                       
        {  

我知道标准库没有任何问题,为什么它会引发错误?

I know there cannot be anything wrong with the standard library so why is it throwing an error?

这是我得到的最接近的答案: https://github.com/PacificBiosciences/pbbam/issues/14

This is the closest I got to some answer: https://github.com/PacificBiosciences/pbbam/issues/14

似乎答案围绕着这些"Dprivate"和"Dpublic"标志.我假设是编译器标志,但是我不确定它们的作用.

And it seems the answer revolves around these "Dprivate" and "Dpublic" flags. Which I assume are compiler flags, but I'm not sure what they do.

推荐答案

尽管github上的线程很引人注目,但似乎错过了原因.您很可能在项目中构建一些单元或其他测试,以重新定义"private"关键字,如下所示:

Although the thread at github hits the spot, it seems to miss the reason. You most likely are building some unit or other tests in your project that redefine the 'private' keyword like so:

#define private public

或者通过(-Dprivate=public)之类的命令执行相应的操作.这是在不使测试代码依赖测试代码的情况下公开私有成员进行测试的常用做法. 但是,请查看您的片段.无论您对private的定义如何,第一个都将__xfer_bufptrs声明为私有.下一个第二个代码段肯定是(尽管未检查)在显式的private块中.现在,如果您对private的定义正确了,您将在第二个片段中使用public进行修饰,这是一个错误.

Or do the respective thing via command like (-Dprivate=public). This is a commonly used practice to expose private members for testing without making the tested code dependent on the testing code. However look at your snippets. The first one declares __xfer_bufptrs as private regardless of your definition of private. Next second snippet is surely (haven't checked though) in an explicit private block. Now if your definition of private is in place you will ned up with public in the second snippet which is a fault.

您至少有两个选择,其他当然也可以:

You have at least two options, other are surely also possible:

  1. #undef在包含系统头之前先定义私有定义,然后在包含系统头之后再次定义,或者
  2. 您使用另一个宏来定义自己的私有/公共部分,例如:#define my_public public,可以随意重新定义.这个解决方案虽然看起来很讨厌;)
  1. You #undef the private definition before including system headers and define again after inclusion of those, or
  2. You use another macro to define your own private/public sections e.g.: #define my_public public which can be redefined at will. This solution seems icky though ;)

哦,为了将来在您自己的代码中使用,请始终使用显式访问权限来避免这种麻烦,至少与您自己的代码一样:)

Oh and for the future in your own code always use explicit access qualification to avoid this sort of mess at least with your own code :)

这篇关于用公共访问编译器错误重新声明了sstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆