Thread: Passing by reference.

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    46

    Passing by reference.

    This is the basic of basics, but for some reason I keep getting the compile error

    Code:
    error C2143: syntax error : missing ')' before '&'
    Code:
    int file_read(ang_file *f, _TCHAR *buf, size_t n, size_t &n_read)
    {
    ... function goes here ...
    }
    All I wanted to do was change the file_read function so that it returned an number for error (or success) and stored the number of bytes read through a variable passed to it.

    I'm new to C++ programming so if I've missed something very obvious please let me know.

  2. #2
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    that error usually means it doesn't recognize a type in your arg list

    what did the function look like before?

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    46
    Quote Originally Posted by m37h0d View Post
    what did the function look like before?
    Like ...

    Code:
    int file_read(ang_file *f, _TCHAR *buf, size_t n)
    as far as I recall. There are other size_t's and _TCHAR's in the same file so I'd be surprised if they were the problem.

    Yeah, it's definitely the & that isn't being liked there. Changing everything else doesn't kill the compile error.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> Yeah, it's definitely the & that isn't being liked there. Changing everything else doesn't kill the compile error.

    Why don't you post a small, compilable example that demonstrates the problem?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Are you compiling the code as C code (i.e., does the name of the file end in ".c")? Because C doesn't have references.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    46
    Quote Originally Posted by dwks View Post
    Are you compiling the code as C code (i.e., does the name of the file end in ".c")? Because C doesn't have references.
    D'oh! Yeah, it's "Compile as C++ Code (/TP)" but .c files. I forgot about that.

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