simple class and im confused>.<

hi am trying to construct a simple class put im verey confused
i did this coad for now for me i dont see anything rong but for the compiler
there must be an error iv tried this prog 2 ways
in oop and this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//this program will contain structure of array and class
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

class cal
{
private:
	struct students
	{
		int id;
		int tcrd;
		float gpa;
		string dep;
	};//creating an structuter
	students arr[50];
public:
  cal(students arr[50])
  {
	cout <<"im in the costructor function\n"
		<<"mu duaty is to red from file and inilize the array of structure\n";
   }
	void serch(students arr[50],int &numUsed)
   {
	cout <<"im in function serch\n"
		<<"mu douty is to serch for agiven student data\n";
   }
	
  void show(students arr[50],int &numUsed)
  {
	cout <<"im in function show \n"
		<<"my douty is to show all the data of students";
  }
};

int main()
{
	cal ob1;
	int numUsed;
	ob1.cal(arr[50]);
	ob1.serch(arr[50],numUsed);
	ob1.show(arr[50],numUsed);
	return 0;
}


put it seems that the compiler dose not recognize that am declaring a class!!!
it says :'cal' : no appropriate default constructor available !!!
can any one tell me what should i do?!
thanks in advance.
Last edited on
...and why arr[50] is undeclared identefier and im declaring it in the class...
should i put the structure above the main and declare the array of structre inside the main!!!
1. If you the programmer provide a constructor that thakes parameters, then you the programmer
is responsible for providing a default constructor if one is required.

This applies to you, bcause you made this constructor for cal(students arr[50]) which is a constructor taking parameter(s), but you tried to create a cal object using the default constructor here cal ob1;

You need to do one of two things:
a. provide a default constructor
b. Only create a cal object using the constructors you have provided.



2.
1
2
3
	ob1.cal(arr[50]);
	ob1.serch(arr[50],numUsed);
	ob1.show(arr[50],numUsed);

You need to create a student array in main and pass it to the functions - basically the same way you you have done with the int numUsed;

Attempting this ob1.cal(arr[50]); is also wrong and an illegal use of a constructor.

You need to to go a do some serious revision/study


Last edited on
Topic archived. No new replies allowed.