2012-12-03 66 views
0

我在做這個項目,我不得不採取從文件到一個矢量輸入,然後掰開該向量和發送它的元素融入到一類。我試圖建立一個班級人員的測試,但當我嘗試這樣做時,我收到了這個錯誤。「不匹配功能呼叫」錯誤

錯誤:

C:\Users\Eric\Dropbox\CSE 2122 - C++\Project Files\Homework09\main.cpp:57: error: no matching function for call to `person::person(int, std::vector<int, std::allocator<int> >&)' 
C:\Users\Eric\Dropbox\CSE 2122 - C++\Project Files\Homework09\main.cpp:9: note: candidates are: person::person(const person&) 
C:\Users\Eric\Dropbox\CSE 2122 - C++\Project Files\Homework09\main.cpp:17: note:     person::person(int, std::vector<float, std::allocator<float> >) 

Main.cpp的

#include <iostream> 
#include <fstream> 
#include <vector> 

using namespace std; 

/* Person Class */ 
class person 
{ 
    public: 
     int id; 
     vector <float> scores; 
     float averageScore; 

    /* Person Constructor */ 
    person(int _id, vector<float> _scores) 
    { 
    id = _id; 
    scores = _scores; 

    int total; 

    for(unsigned int i = 0; i < _scores.size(); i++) 
    { 
     total += _scores[i]; 
    } 

    averageScore = (total/_scores.size()); 
    } 
}; 

/* Function Prototypes */ 
string getFileName(); 
void readFile(string fileName, vector <int> &tempVec); 

/* Main */ 
int main() 
{ 
    vector <int> tempVec; 
    vector <int> tempVec2; 

    tempVec2.push_back(56); 
    tempVec2.push_back(98); 
    tempVec2.push_back(78); 
    tempVec2.push_back(89); 

    int personCount = 0; 

    vector <person> personVector; 

    string fileName = getFileName(); 

    readFile(fileName, tempVec); 

    personCount = (tempVec.size())/(4); 

    person eric = person(110, tempVec2); 


} 

/* getFileName Function */ 
string getFileName() 
{ 
    string fileName; 
    cout << "Enter the file you wish to read from: "; 
    cin >> fileName; 

    return fileName; 
} 

/* readFile Function */ 
void readFile(string fileName, vector <int> &tempVec) 
{ 
    float x = 0; 

    ifstream fin; 

    fin.open(fileName.c_str(), ios::in); 

    if(!fin.is_open()) 
    { 
     perror(fileName.c_str()); 
     exit(10); 
    } 

    while(!fin.fail()) 
    { 
     fin >> x; 
     tempVec.push_back(x); 
    } 

    fin.close(); 
} 

有什麼想法?

回答

2

person構造函數採用floatvector一個s,而你試圖傳遞tempVec2到它,這是intvector秒。

+0

哇...謝謝。我一直在盯着那個永遠,有時候別人只需要看一看就發現一個愚蠢的錯誤。 – malibubts