Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

access voilation error

Status
Not open for further replies.

oconv

Programmer
Jan 17, 2002
25
ZA
Hi All,

I'm not a regular C++'er , so maybe this will be easy.

I have 3 classes Driver , Savings & Customer.
Savings public inherits Customer.
The varibles in Customer is CustNumber (char*)
CustName, (char*)
CustTelNo. (long)

The Savings class has a constructor that accepts a char* it looks like this :

Savings(char* TempCustNum):Customer(TempCustNum){};

and then the Customer Constructor looks like this:

Customer(char* TempCustNum){
CustNumber = TempCustNum;
cout << &quot;Enter the Customer number&quot;;
cin >> CustName;
}

so this is what happens

In the driver I ask for a customer number , get it & then
constuct a instance of the savings class with the number that i just got from the user , the Savings class's constructor then calls the Customer class constructor , withc then set the CustNumber varible , & then asks for a Name , this is where the error steps in the moment I press Enter after I typed in the Customer Name

It goes back to the Borland compiler with a message box and says something about a execption error occured & give some memmory adress.

PLEASE HELP ME OUT OF MY MISSERY , I have no idea what to do. :-(

Thanks




 
Have you reserved some memory for the name ?
With char* you only have a pointer that has to point
to a location in memory where there is reserved space for the name. If you do not allocate memory , the pointer contains garbage.
Instead of char*, take char[256] for your name.
Then you don't have to worry about freeing it either when it is no longer used.
Greetz,

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top