Frustrating syntax problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sejoro
    New Member
    • Feb 2008
    • 9

    #1

    Frustrating syntax problem

    At this point in life, I thought syntax wouldn't be a problem, but it is. I'm trying to write yet another school program, but keep getting compile errors in the main function when I try to pass an array of structs to any other function. The error is operand expected instead of ",", and at this point I've managed to get it down to one error. What am I doing wrong? I've tried everything. Here are the two lines in their current form:

    count(AofS[0], count&, total&);
    print(AofS[0]);

    Like I said this is the only error I'm getting and it's frustrating me. This program is late because of this one little problem...
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You didn't post the function prototypes of these functions you are calling so this may be an incomplete answer.

    1) a count& is a reference. Did you mean to pass the address of count? Like maybe it should be &count??

    2) if these functions are passed an array of structs, you can just use the array name. In C++, the array name is the address of element 0. So you could pass the address of element 0 as &AofS[0] instead of using the array name.

    It all comes down to the function prototype (which you didn't post) because it is there the type of the arguments is defined.

    Comment

    • Sejoro
      New Member
      • Feb 2008
      • 9

      #3
      void count(frequency , int&, int&);
      void print(frequency );

      Those are the prototypes. Frequency is a struct in a header file.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        So then you call the function this way:
        [code=cpp]
        count(AofS, count, total);
        //or
        count(&AofS[0], count, total);
        [/code]

        Your print function only has one argument for the array. How does it know how many elements are in the array? Or does it just print one element?

        Comment

        Working...