Thread: passing by reference

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    24

    passing by reference

    what's wrong with this? I get this error: The error refers to the red line.

    error: incompatible types in assignment
    (in my header file)
    Code:
    #define MAX_TEST 80;
    
    typedef struct {
        char aString[MAX_TEXT-1];
        int anInt;
        double aDouble;
    } Lab10Struct;
    (in other file -- not the whole file, just the parts i have questions about)

    Code:
    Lab10Struct passByReference( Lab10Struct *variable )
    {
        strcat(variable->aString, "Hello again, do you like my hat?");
    
        variable->anInt -= 123456789;
    
        variable->aDouble -= 1.23456789;
    
        return *variable;
    }
    
    int main()
    {
       Lab10Struct *ptr, s1;
    
       ptr = passByReference(&s1);
    
       if (ptr != &s1)
       {
          printf("Failed test #4\n");
          pass = 0;
       }
    
       return 0;
    }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Your function returns an object, not a pointer.
    Code:
    #define MAX_TEXT 80 /* no semicolon*/
    
    typedef struct {
        char aString[MAX_TEXT-1];
        int anInt;
        double aDouble;
    } Lab10Struct;
    
    Lab10Struct* passByReference( Lab10Struct *variable )
    {
        strcat(variable->aString, "Hello again, do you like my hat?");
    
        variable->anInt -= 123456789;
    
        variable->aDouble -= 1.23456789;
    
        return variable;
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    24
    Quote Originally Posted by Dave_Sinkula
    Your function returns an object, not a pointer.
    EDIT: nevermind, I didn't see that you made the function a pointer...I didn't catch that. Thanks for the help. It worked

    And thanks about that #define thing...i just wrote that quickly in my post and messed up...I didn't copy it from my code. It's written fine there
    Last edited by mapunk; 11-30-2005 at 10:41 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM