源檔案如下:
#include<iostream>
#include<vector>
#include<string>
#include "Student_info.h"
#include "grade.h"
std::istream& read_hw(std::istream& in, std::vector<double> hw)
{
if(in)
{
double x;
hw.clear();
while(in >> x)
hw.push_back(x);
in.clear();
}
return in;
}
bool compare(const Student_info& x, const Student_info& y)
{
return x.grade() > y.grade();
}
std::istream& Student_info::read(std::istream& in)
{
in >> n >> midterm >> final;
read_hw(in, homework);
return in;
}
double Student_info::grade() const
{
return ::grade(midterm, final, homework);
}
頭檔案:
#ifndef GUARD_Student_info_h
#define GUARD_Student_info_h
#include<iostream>
#include<vector>
#include<string>
#include "grade.h"
class Student_info
{
public:
std::istream& read(std::istream&);
std::string name() const{return n;}
double grade() const;
private:
std::string n;
double midterm, final;
std::vector<double> homework;
};
std::istream& read_hw(std::istream&, std::vector<double>);
bool compare(const Student_info&, const Student_info&);
#endif
uj5u.com熱心網友回復:
頭檔案定義寫完整,&后面的變數呢?,vector變數?源檔案傳引數直接傳變數名,不帶型別,你這不是沒定義,是重定義,重復去定義了那個函式或變數uj5u.com熱心網友回復:
報哪個重復定義了, 沒看出來哪個重復定義。uj5u.com熱心網友回復:
你少貼了一個grade.h。原因可能在這個頭檔案里面uj5u.com熱心網友回復:
謝謝大家,已經成功運行了,我重新創建了一個專案,代碼復制過去就好了轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/82080.html
標籤:C++ 語言
下一篇:c++代碼請教
