Thread: Class Function Help

  1. #1
    The Maverick Programmer
    Join Date
    Jan 2005
    Posts
    10

    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?
    Conformity in the Code is a Calculated error in Compilation.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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++;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Possible problems:

    1. Capitalization errors (case-sensitivity)
    2. Including an outdated header file
    3. Not rebuilding all the correct source files
    4. There's a bug in your code elsewhere (maybe a missing parenthesis or semicolon) that's causing this code to act funny

  4. #4
    The Maverick Programmer
    Join Date
    Jan 2005
    Posts
    10
    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.
    Conformity in the Code is a Calculated error in Compilation.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    The Maverick Programmer
    Join Date
    Jan 2005
    Posts
    10
    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.
    Last edited by Team Shadow V2; 04-02-2005 at 04:15 AM.
    Conformity in the Code is a Calculated error in Compilation.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  4. class errors
    By romeoz in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2003, 07:57 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM