嘗試使用函數來查找向量的中值時,出現一些瘋狂的錯誤。我不完全確定是什麼導致了這些錯誤。運行函數時發生錯誤
- '錯誤1錯誤C2601: 'calcMed':本地函數的定義是非法的'
我試圖使用聲明爲
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
using namespace std;
double calcMed(int, vector<int>& studentScores);
//
double homeworkMed = calcMed(vectorSize, studentScores);
double calcMed(int vectorSize, vector<int>& studentScores)
{
double median;
sort(studentScores.begin(), studentScores.end());
median = studentScores[vectorSize/2];
return median;
}
我知道,它的功能如果我有一個奇怪的矢量,但我只是想讓這第一個工作。任何幫助,將不勝感激。
刪除了「double calcMed(int vectorSize,vector & studentScores)」中的分號,現在我得到兩個不同的錯誤,它們都在函數名稱後面的行中。
的錯誤都發生在符合{
double calcMed(int vectorSize, vector<int>& studentScores)
{
您確定沒有涉及'calcAverage'嗎?給我們一個[最小完整的例子](http://sscce.org),我敢打賭問題會很明顯。 – Beta
除非您嘗試在'main'中定義它,否則這是如何編譯的? – chris
@chris它沒有。 CNR。 「P – WhozCraig