Find the answer to your Linux question:
Results 1 to 9 of 9
Ok first off I am in CompSci I at college and this is a problem with a program I am doing. I have a struct with 2 strings, 3 floats, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2002
    Location
    US
    Posts
    7

    struct problems


    Ok first off I am in CompSci I at college and this is a problem with a program I am doing.

    I have a struct with 2 strings, 3 floats, and 3 int arrays. Plus I have a bunch of structs in one array.
    Anyhow I am trying to sort the array of structs into order based on one of the floats. I know the process what I am having problem with is I am getting 2 errors I don't know how to fix. I am unfamiliar with structs so it may be just that.

    #1: In my int main() I am trying to call a funtion using my main array and I am getting this error:Error 406: "FinalLab.cc", line 108 # Argument type 'StudentInfo *' does not match expected parameter type 'student *'; '
    struct StudentInfo' is not an unambiguously derived class of 'tentative struct student'.
    SortByTestAverage(student, studentNumber);
    I am using "void SortByTestAverage(struct student[], int& studentNumber);"

    #2: In my funtion that swaps the info between two indexes in my array I am getting this: Error 24: "FinalLab.cc", line 121 # '<identifier>' expected instead of 'student'.
    nameTemp=student[cs].first;
    This confuses the hell out of me and I am using a similar viod to #1

    oh I found another the "cs" up there in 2 is a global variable that is getting: Error 249: "FinalLab.cc", line 122 # Subscript operator must have pointer to object and integral operands; 'int[int]' was found.

    any help with my homework would be wonderfull hehe.

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Your code looks very strange. Post the entire program (or, even better, a link to it if possible) so that we can actually see what's wrong.

  3. #3
    Just Joined! Sykotik's Avatar
    Join Date
    Mar 2002
    Location
    Cape Town, South Africa
    Posts
    54

    Re: struct problems

    Quote Originally Posted by Speranza
    Error 406: "FinalLab.cc", line 108 # Argument type 'StudentInfo *' does not match expected parameter type 'student *'; '
    struct StudentInfo' is not an unambiguously derived class of 'tentative struct student'.
    SortByTestAverage(student, studentNumber);
    I am using "void SortByTestAverage(struct student[], int& studentNumber);"
    I'm guessing you're supposed to actually specify which structure student[] should be, e.g. "struct StudentInfo student[]"... I could be wrong though. There's not much you're giving to work with...

    Quote Originally Posted by Speranza
    #2: In my funtion that swaps the info between two indexes in my array I am getting this: Error 24: "FinalLab.cc", line 121 # '<identifier>' expected instead of 'student'.
    nameTemp=student[cs].first;
    Compiler errors tend to pile up, so if the error as I interpreted is correct, fixing the first problem in both functions should make the bad text go away

    Quote Originally Posted by Dolda2000
    Post the entire program (or, even better, a link to it if possible) so that we can actually see what's wrong.
    That would be a very good idea, yes.

  4. #4
    Just Joined!
    Join Date
    Oct 2002
    Location
    US
    Posts
    7
    I will see what I can do about posting a copy of the program. I am out of town for the weekend so see you all monday

  5. #5
    Just Joined!
    Join Date
    Oct 2002
    Location
    US
    Posts
    7
    http://www.angelfire.com/tn2/victorsperanza/C__.txt

    That is my program in total. Sorry about the angelfireness but being poor means no good webspace for me.

  6. #6
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    I think I see the problem. It seems to be because the file is named FinalLab.cc. The .cc extension indicates to a compiler that it should be written in "objective C", which is not the same as C++. When I renamed the file to FinalLab.cpp, it compiled perfectly and I could run it.

  7. #7
    Just Joined!
    Join Date
    Oct 2002
    Location
    US
    Posts
    7
    Hmm odd it didn't fix a thing for my. Well I am moving the program to a different computer (Mine with mandrake) later to try it cause there is the possibility that it is the compiler on the computer I am using(Schools ancient computer that is very large in size and I am sure has tape wheels).

    See my new post in linux workstation -> application to watch my slow progress of getting my linux box working

  8. #8
    Just Joined!
    Join Date
    Oct 2002
    Location
    US
    Posts
    7
    no make that installation forum hehe

  9. #9
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Tape wheels... lol! Well, the error messages looked like no compiler that I recognized.
    Just remember to rename the file to FinalLab.cpp instead of FinalLab.cc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •