Access violation reading location

Hi everyone!

My code builds fine but I'm getting the error:
First-chance exception at 0x00995CA7 in PcppAssingment(NG CHUNG NENG TP028902).exe: 0xC0000005: Access violation reading location 0x0124ADE4.
Unhandled exception at 0x00995CA7 in PcppAssingment(NG CHUNG NENG TP028902).exe: 0xC0000005: Access violation reading location 0x0124ADE4.

My constructors, destructors, copyconstructor and overloaded assignment operator should be correct so I have no idea why this happens.


There's something about a bad pointer, that's all I've figured out.



Thanks.

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
  void Teacher::Display(){
		cout<<"\tTeacher:"<<endl;
		cout<<"\tYr id:"<<Userid<<endl;
		cout<<"\tYr Password:"<<UserPassword<<endl;
		cout<<"\tYr Name:"<<UserName<<endl<<endl;
		cout<<"\tYr Contact Number:"<<contactnumber<<endl<<endl;


Activity::Activity(){
}
Activity::Activity(int aid,string n,string ty,int f,Teacher ta,Date d): activityid(aid),name(n),type(ty),fee(f),teacherassigned(ta),activitydate(d)
	{}

void Activity::displayacctivities(){
	cout<<"Activity id: "<<activityid<<endl;
	cout<<"Activity name: "<<name<<endl;
	cout<<"Activity type: "<<type<<endl;
	cout<<"Activity fee: "<<fee<<endl;
	cout<<"Activity Incharge: ";teacherassigned.Display();
	cout<<"Activity Date: ";activitydate.toString();
}


void Staff::viewactivitys(){
		 Activity obj;
          ifstream fp;
         fp.open("Activity.dat",ios::binary);
          while(fp.read((char*)&obj,sizeof(obj)))
          {
                   obj.displayacctivities();
          }
       
		    
		  cout<<"Please press ENTER to back to the menu ...";
			cin.ignore();
			cin.get();
	}
Line 28: You cannot read an object that contains non primitive(POD)/pointer members that way.
may guide me what to do??
[i]fstream is similar to cin/cout. Use can use the operator>> (or getline(...)) to read and the operator<< to write the data like you'd do with cout/cin. Just omit the overhead.
i'm sorry that i am newbie


may show me how to edit it? how can i use operator to read a object's data from another class and display it ?
Last edited on
For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void Activity::readacctivities(istream &is){
	is >> activityid;
	is >> name;
	is >> type;
	is >> fee;
	teacherassigned.Read(is);
	activitydate.Read(is);
}


void Staff::viewactivitys(){
		 Activity obj;
          ifstream fp;
         fp.open("Activity.dat",ios::binary);
          obj.readacctivities(fp);
          obj.displayacctivities();
       
		    
		  cout<<"Please press ENTER to back to the menu ...";
			cin.ignore();
			cin.get();
	}

	
Topic archived. No new replies allowed.