-
Class Function Help
Hey I'm having a very, very minor syntax error in one of my class functions that I cannot detect. Here's a sample code.
Code:
void cclass::cfunction() {
if (var1 != OneArray [x] && var1 < OneArray [x])
x + 1;
cfunction();
else if (var1 != OneArray [x] && var1 > OneArray [x])
x - 1;
cfunction();
}
OneArray is an array that is already defined in the public section of the class cclass. I'm using Dev C++ 4.9.9.0 and it says OneArray is undeclared, first use in the function. I don't know why this is happening becuase I have used OneArray numerous times in two other class functions, but now it seems something is wrong with my syntax, so could someone lend me a hand please?
-
It needs some braces
Code:
if (var1 != OneArray [x] && var1 < OneArray [x]) {
x + 1;
cfunction();
}
Also, x + 1 doesn't do anything as such (adds one to x and throws the answer away)
So it should be
x = x + 1;
or perhaps even
x++;
-
Possible problems:
- Capitalization errors (case-sensitivity)
- Including an outdated header file
- Not rebuilding all the correct source files
- There's a bug in your code elsewhere (maybe a missing parenthesis or semicolon) that's causing this code to act funny
-
I've checked all of your possibilities, and #4 seems to be the best case. However, I can't seem to get the syntax correct. I had a similar problem once. Would someone mind showing me the proper way of how to put in the parentheses. I'm very sure this is the culprit of my afairs. Oh, and I was copying from an older source, the x + 1 was supposed to have an x = in front of it.
-
> Oh, and I was copying from an older source, the x + 1 was supposed to have an x = in front of it.
Well that's a good way of getting unhelpful answers.
Posting older versions of the code, code you've edited and not compiled, or code recited from memory just wastes everyones time.
-
It should be noted that the only difference between my older source and my newer one was the missing x = code. And I do not see how in this case it wastes time, as that is not part of my overall problem. If I must, I restate my position. The variable array OneArray in function cfunction gets an error when I compile it. OneArray is suppossed undeclared. I assume this is due to syntax error in if statement parenthesis, but I can not figure out exactly how. Again the x variable doesn't even have to matter really.
EDIT: Hmm. Nevermind. I figured it out. It was something screwy with the parenthesis, but one of the other functions in the class was messing with it.
-
> Hey I'm having a very, very minor syntax error
Which means if your post is not totally 100% accurate with respect to your question, your post is meaningless.
Because everyone is going to pick up on something which isn't going to be the answer you seek.
Programming is a very precise discipline. Sloppy questions and inaccurate or incomplete evidence will just get you nowhere.