簡體   English   中英

收到此錯誤:我該如何解決?

[英]Getting this error: how can I solve this?

我是編程新手我該如何解決這個錯誤有人可以幫助我嗎? 自己嘗試過,但無法! 我嘗試更改變量數據類型,但遇到其他錯誤。 請建議我該怎么做才能解決此錯誤。

#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

int main()返回一個int類型的值,但返回std::vector<my_complex>類型的變量result

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM