g ++发出难以理解的警告

时间:2019-05-19 09:16:09

标签: c++ gcc operator-overloading language-lawyer friend

system.h:

#include <iostream>

namespace ss
{
  class system
  {
  private:
    // ...
  public:
    // ...
    friend std::ostream& operator<< (std::ostream& out, const system& sys);

   };
}

system.cpp:

#include "system.h"

std::ostream& ss::operator<< (std::ostream& out, const ss::system& sys)
  {
    // print a representation of the ss::system
    // ...
    return out;
  }

使用g ++ 8.30编译上述代码会产生以下输出:

[db@dbPC test]$ LANG=en g++ -Wall -Wextra system.cpp
system.cpp:2:15: warning: 'std::ostream& ss::operator<<(std::ostream&, const ss::system&)' has not been declared within 'ss'
 std::ostream& ss::operator<< (std::ostream& out, const ss::system& sys)
               ^~
In file included from system.cpp:1:
system.h:11:26: note: only here as a 'friend'
     friend std::ostream& operator<< (std::ostream& out, const system& sys);
                          ^~~~~~~~
system.cpp: In function 'std::ostream& ss::operator<<(std::ostream&, const ss::system&)':
system.cpp:2:68: warning: unused parameter 'sys' [-Wunused-parameter]
 std::ostream& ss::operator<< (std::ostream& out, const ss::system& sys)
                                                  ~~~~~~~~~~~~~~~~~~^~~

编译器告诉我,operator<<函数未在命名空间ss中声明。但是在该名称空间中声明的。

我还尝试使用clang++进行编译。 clang仅抱怨未使用的参数,却抱怨,关于我不明白的“不在命名空间中”问题。

g++警告的原因是什么?这是错误的警告吗?

版本:

g++ (GCC) 8.3.0
clang version: 8.00 (tags/RELEASE_800/final)

1 个答案:

答案 0 :(得分:5)

您只是错过了在data.append('file', file); const files_related_data = [ { name: "n1", description: "d1", business_file_type: 1 } ]; const project_id = 1; data.append('files_related_data', files_related_data); data.append('project_id', project_id); const allData = data; 中声明=ARRAYFORMULA(IF(LEN(A1:A); SUBSTITUTE(TRANSPOSE(QUERY(TRANSPOSE(IFERROR(REGEXEXTRACT(SPLIT(A1:A; " "); "\b[\w]"))); ; 999^99)); " "; ); ))

尝试以下操作:

operator <<