c++ - std::reverse_copy "error: function call has aggregate value"

标签 c++ stl

#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;

int main()
{
  int arrA[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  vector<int> vecIntA(arrA, arrA+sizeof(arrA)/sizeof(arrA[0]));

  vector<int> vecIntB(vecIntA.size());

  //copy((vecIntA.rbegin()+3).base(), (vecIntA.rbegin()+1).base(),  vecIntB.begin()); // OK    

  vector<int>::iterator s = (vecIntA.rbegin()+3).base();
  vector<int>::iterator e = (vecIntA.rbegin()+1).base();
  cout << "s: " << *s << ", e: " << *e << endl;
  reverse_copy(s, e,  vecIntB.begin()); // error: function call has aggregate value

  //copy(vecIntB.begin(), vecIntB.end(), ostream_iterator<int>(cout, ","));
  cout << endl;
}

问题>如何解决“error: function call has aggregate value”的问题?

以上代码在VS2010下有效,但在ubuntu12.04 + clang++3.2或g++4.6.3下无效

谢谢

//更新//

//引用:Flags to enable thorough and verbose g++ warnings

g++ $1.cpp -o $1 -g -O -Wall -Weffc++ -pedantic  \
-pedantic-errors -Wextra  -Wall -Waggregate-return -Wcast-align \
-Wcast-qual  -Wchar-subscripts  -Wcomment -Wconversion \
-Wdisabled-optimization \
-Werror -Wfloat-equal  -Wformat  -Wformat=2 \
-Wformat-nonliteral -Wformat-security  \
-Wformat-y2k \
-Wimport  -Winit-self  -Winline \
-Winvalid-pch   \
-Wunsafe-loop-optimizations  -Wlong-long -Wmissing-braces \
-Wmissing-field-initializers -Wmissing-format-attribute   \
-Wmissing-include-dirs -Wmissing-noreturn \
-Wpacked  -Wpadded -Wparentheses  -Wpointer-arith \
-Wredundant-decls -Wreturn-type \
-Wsequence-point  -Wshadow -Wsign-compare  -Wstack-protector \
-Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch  -Wswitch-default \
-Wswitch-enum -Wtrigraphs  -Wuninitialized \
-Wunknown-pragmas  -Wunreachable-code -Wunused \
-Wunused-function  -Wunused-label  -Wunused-parameter \
-Wunused-value  -Wunused-variable  -Wvariadic-macros \
-Wvolatile-register-var  -Wwrite-strings \
-std=c++0x

最佳答案

-Waggregate-return -Werror 

您指定返回聚合值是一个错误。虽然理论上不是。

-Waggregate-return
Warn if any functions that return structures or unions are defined or called. (In languages where you can return an array, this also elicits a warning.)

你可能想删除这个标志

关于c++ - std::reverse_copy "error: function call has aggregate value",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17160515/

相关文章:

c++ - 使用 LinkedList 检查值

c++ - 为什么 ostream 不能转换为 ostream?

c++ - C++ 中的 unordered_map 插入是如何工作的?

c++ - 在 ‘begin’中请求成员 ‘c’,它是非类类型 ‘char [101]’ sort(c.begin(),c.end());

C++,OpenCV : Fastest way to read a file containing non-ASCII characters on windows

c++ - vector 迭代编译成非常不同的指令

c++ - std::vector<std::pair<const int, const int>>::clear() VS 2010 无编译

c++ - 没有 RTTI 的 shared_ptr?

c++ - 通用 Future/Promises 的容器

c++ - C++ 中的映射导致错误