2012-12-03 67 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