Skip to main content
gamedev.net
🔒 Locked

help with classes

Started by omegasyphon Apr 18, 2001 at 11:11 AM 2 replies 250+ views
Original Post
omegasyphon
omegasyphon
ok when i compile my program i get the following errors error C2440: ''='' : cannot convert from ''char [1]'' to ''char'' This conversion requires a reinterpret_cast, a C-style cast or function-style cast error C2059: syntax error : '')'' my first error says i cant do this in my classes constructor
  
cardata::cardata()
{
	model[20]= "";
 	maker[30]= "";
	year=0;
}
  
the second im not sure cause it just points to the for loop declaration but their is nothing wrong with it
  

void cardata::scandata()
{
	int x=0;
	fin.open("data.dat", ios::in);
	while ( !fin.eof())
	{
		for (x=0;x<20;x++)
			fin>>maker[x];
		
		for (x=0;x<30;++)      //it points to here

			fin>>model[x];

		fin>>year;
	}

	fin.close();
}
  
Ironblayde
Ironblayde
model[20]= "";

I assume this is an array of characters. You can''t make an assignment like that unless you''re doing it on the same line which declares the variable. Use strcpy() instead.

for (x=0;x<30;++)

You forgot the variable name in your increment statement. It should say "x++", not just "++".

-Ironblayde
 Aeon Software

Down with Tiberia!
"All your women are belong to me." - Nekrophidius
"Your superior intellect is no match for our puny weapons!"
omegasyphon
omegasyphon
dam that x was sneaky
so do this strcpy(model[20],"20 spaces");
Grugnorr
Grugnorr
I think there is another error, but I can´t be sure without having a look at the arrays declaration:
///////////
cardata::cardata()
{
model[20]= "";//Accessing position 20
maker[30]= "";//30
year=0;
}

You do access to indices 20 and 30 of those arrays.
/////////////
for (x=0;x<20;x++)//00..19
fin>>maker[x];
for (x=0;x<30;++) //0..29
fin>>model[x];

////
You just loop until 19 and 29, SO I guess you have declared your arrays of 20 and 30 elements each.
If you have done:
///
char model[20];
char maker[30];
/////
You will have a violation access error when you fix your arrays initialitation.

This is just a guess, but it reminds me my switch from Pascal to C++. Many many access violations made by me.


Hope to help!


What the hells!
What the hells!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.