#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;
}
Run Code Online (Sandbox Code Playgroud)
问题>如何解决"错误:函数调用具有聚合值"的问题?
上面的代码在VS2010下工作,但不是ubuntu12.04 + clang ++ 3.2或g ++ 4.6.3
谢谢
//更新//
//参考:标志以启用彻底和详细的g ++警告
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
Run Code Online (Sandbox Code Playgroud)
log*_*og0 10
-Waggregate-return -Werror
Run Code Online (Sandbox Code Playgroud)
您指定返回的聚合值是一个错误.虽然理论上并非如此.
-Waggregate-return
如果定义或调用任何返回结构或联合的函数,则发出警告.(在可以返回数组的语言中,这也会引发警告.)
您可能想要删除此标志
| 归档时间: |
|
| 查看次数: |
2425 次 |
| 最近记录: |