我是编程新手,如何解决此错误,有人可以帮助我吗?我自己尝试过,但无法!我尝试更改变量数据类型,但遇到其他错误。请建议我该怎么做才能解决此错误。
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <vector>
#include <complex>
#define assertm(exp, msg) assert(((void)msg, exp))
typedef std::vector<int> int_vector;
typedef double my_float;
typedef std::complex<my_float> my_complex;
typedef std::vector<my_complex> complex_vector;
typedef std::vector<my_float> float_vector;
typedef std::vector<int> int_vector;
typedef std::vector<complex_vector> complex_matrix;
typedef std::vector<int_vector> int_matrix;
void scaleVectorInplace(std::vector<my_complex>& V, my_complex scale){
std::transform(V.begin(), V.end(), V.begin(), [scale](auto s) { return s * scale; });
}
std::vector<my_complex> scaleVector(const std::vector<my_complex>& V, my_complex scale) {
std::vector<my_complex> result = V;
scaleVectorInplace(result, scale);
return result;
}
my_complex qpskmod(int symbol) {
const std::vector<my_complex> mapping {{1,1}, {-1,1}, {1,-1}, {-1, -1}};
return mapping[symbol];
}
int main() {
int symbol;
// Modulate one symbol to its QPSK representation
const complex_vector mapping {{1,1}, {-1,1}, {1,-1}, {-1, -1}};
int_vector symbols;
// Modulate a vector of symbols with is QPSK representation
std::vector<my_complex> result;
//complex_vector result;
result.resize(symbols.size());
// applies QPSK modulation to each symbol in the vector
std::transform(symbols.begin(), symbols.end(),
result.begin(), [](int s) { return qpskmod(s); });
return result;
}
错误:
In function 'int main()':
55:10: error: cannot convert 'std::vector<std::complex<double> >' to 'int' in return
答案 0 :(得分:2)
int main()
返回类型为int
的值,但是您返回类型为result
的变量std::vector<my_complex>
返回值main
表示程序是否成功终止(return 0
)或是否带有某种错误代码但没有复杂的数据结构
从注释中补充另一个问题,您可以如何打印值,您可能需要使用一个简单的函数,例如:
void printResult(std::vector<my_complex> &vec)
{
std::vector<my_complex>::iterator itr = vec.begin();
while (itr != vec.end())
{
std::cout << *itr << std::endl;
itr++;
}
}
您的main
函数的结尾如下:
printResult(result);
return EXIT_SUCCESS; // most likely same as return 0
您也可以在结尾处为return EXIT_FAILURE
添加一个条件