到明天代码工作好,但知道它给出了一个奇怪的错误.. 没有可用的默认构造函数...
我真的不明白这个错误。而且这是第一次体验与这种类型的错误..我已经搜索的问题,但对构造的讨论是先进的水平.. 我是中级,, .. 请帮助检查我的代码.. !!!构造错误。(奇怪的错误)
// 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;
}
你真的可以通过删除所有不相关的代码来改善这个问题。 – juanchopanza 2013-04-09 12:08:41
你是对的juanchopanza,但函数'fetch_id()'和'fetch_name()'是重要的,因为他试图改变结构的数据。 – Zaiborg 2013-04-09 12:10:42
当代码运行良好时,它现在也应该这样做。如果你不想表达什么是明天的状态,你可以告诉今天的变化。 – harper 2013-04-09 12:13:28