我有一个可笑的奇怪问题。当我尝试运行下面的程序时,出现一条错误消息:“错误 C2512:'记录':没有适当的默认构造函数可用”。当我双击它时,它会将我引导到一个名为“xmemory0”的预编译只读头文件。他们是否希望我更改只读文件?这是它引导我访问的文件中的代码段:
void construct(_Ty *_Ptr)
{ // default construct object at _Ptr
::new ((void *)_Ptr) _Ty(); // directs me to this line
}
这是程序:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
const int NG = 4; // number of scores
struct Record
{
string name; // student name
int scores[NG];
double average;
// Calculate the average
// when the scores are known
Record(int s[], double a)
{
double sum = 0;
for(int count = 0; count != NG; count++)
{
scores[count] = s[count];
sum += scores[count];
}
average = a;
average = sum / NG;
}
};
int main()
{
// Names of the class
string names[] = {"Amy Adams", "Bob Barr", "Carla Carr",
"Dan Dobbs", "Elena Evans"};
// exam scores according to each student
int exams[][NG]= { {98, 87, 93, 88},
{78, 86, 82, 91},
{66, 71, 85, 94},
{72, 63, 77, 69},
{91, 83, 76, 60}};
vector<Record> records(5);
return 0;
}