直到明天代码运行良好但知道它给出了一个奇怪的错误..没有可用的默认构造函数..
我真的不明白这个错误..而且这是第一次遇到这种类型的错误..我已经搜索过问题但是关于构造函数的讨论是高级水平..我是中级,,..请帮助检查我的代码.. !!!
// error.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
struct Student
{
const char name[6][11];
const int id[5];
};
void fetch_id(Student& s, const int size)
{
for (int i = 0; i < size; i++)
{
cout << "roll no of student: " << i+1 << endl;;
cin >> s.id[i];
}
}
void fetch_name(Student& s, const int size)
{
for (int j = 0; j < size; j++)
{
cin.getline(s.name[j], 10);
cout <<"name of student: " << j+1 << endl;
}
}
void display_name(Student s, const int size)
{
cout << "Student Names Are" << endl;
for (int i = 0; i < size; i++)
{
if ( s.name[i] != '\0' )
cout << s.name[i] << endl;
}
}
void display_id(Student s, const int size)
{
cout << "Roll Numbers Are" << endl;
for (int i = 0; i < size; i++)
{
cout << s.id[i] << " || ";
}
}
int main()
{
const int size = 5;
Student s; // error C2512: 'Student' : no appropriate default constructor available ??
fetch_id(s, size);
display_id(s, size);
cout << '\n';
fetch_name(s, size);
cout << '\n';
display_name(s, size);
system("Pause");
return 0;
}