Can't figure out what's wrong with Function's Arguments

This is a discussion on Can't figure out what's wrong with Function's Arguments within the C++ Programming forums, part of the General Programming Boards category; The first function I'm using is named Request This function calls another function named PKADEN. Request/ Code: int PKADEN(char *, ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Can't figure out what's wrong with Function's Arguments

    The first function I'm using is named Request

    This function calls another function named PKADEN.

    Request/

    Code:
    int PKADEN(char *, char *, char *, double &);
    
    char s[100];
    char ErrorMsg[150];
    char PKADetail[500];
    double FinalPKA;
    
    PKADEN(s,ErrorMsg,PKADetail,&FinalPKA);
    PKADEN/

    Code:
    int pkaden(char *s, char *ErrorMsg, char *PKADetail, double *FinalPKA)
    Everything seems to be set up correctly, but when I try to compile it I get the following error:
    Code:
    Request - error C2664: 'pkaden' : cannot convert parameter 4 from 'double *__w64 ' to 'double &'
    I'm using Visual Studio 2005 on Windows.

    Thanks

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    Your prototype declares a reference, but your definition and invocation use a pointer.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Thanks

    Thanks for the info. I'm still pretty new to C++ and a little confused. Here's
    what I came up with based on what you told me and it compiled:

    request/
    Code:
    double FinalPKA; 
    double *pFinalPKA = &FinalPKA;
    char s[100];
    char ErrorMsg[150];
    char PKADetail[500];
    
    int pkaden(char *,char *,char *,double *);
    
    pkaden(s,ErrorMsg,PKADetail,pFinalPKA)
    PKADEN/

    Code:
    int pkaden(char *s, char *ErrorMsg, char *PKADetail, double *pFinalPKA)

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    If you have a reference, you don't need to use the & operator when you call the function, it's all hidden from you
    Code:
    int PKADEN(char *, char *, char *, double &);
    char s[100];
    char ErrorMsg[150];
    char PKADetail[500];
    double FinalPKA;
    PKADEN(s,ErrorMsg,PKADetail,FinalPKA);
    But like a pointer, changes to the variable inside the function will appear in your variable.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with functions using variables as arguments
    By kristentx in forum C++ Programming
    Replies: 2
    Last Post: 03-29-2006, 09:36 AM
  2. Replies: 6
    Last Post: 02-29-2004, 08:47 PM
  3. functions and pointer arguments
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2002, 04:04 PM
  4. Replies: 0
    Last Post: 11-11-2001, 12:24 PM
  5. cant figure out whats wrong with this ....
    By ii3ejoe in forum C++ Programming
    Replies: 17
    Last Post: 10-22-2001, 12:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21