Thread: friends with default values

  1. #1
    Registered User
    Join Date
    Aug 2023
    Posts
    45

    Lightbulb friends with default values

    In my latest endeavor I ran into a friends problem. I've got 2 functions declared and defined with 2 parameters in one file. In another file they and a lot of other functions are declared as friends. These 2 functions have the last parameter declared with a default NULL value.
    Code:
      friend void CheckIntegerOrReal(const TType *pType1,
                       const TType *pType2 = NULL);
      friend void CheckBoolean      (const TType *pType1,
                       const TType *pType2 = NULL)
    I guess the intent was to use these functions with one or two parameters because later in this project both of these functions are called using just one parameter! This kind of makes sense to me. But the compiler doesn't like friends with default parameters. If I take out the = NULL, the compiler is happy! But the calling code below isn't! Not enough parameters.
    Code:
    CheckBoolean(ParseExpression());
    This is the calling code using one return value parameter. The only thing I can think of doing is to change the call with an extra NULL parameter. Any thoughts are definitely welcome on this vexing matter.
    maxcy/wt1v

  2. #2
    Registered User
    Join Date
    Aug 2023
    Posts
    3
    Code:
    // In a different file (e.g., implementation.cpp)
    
    
    #include "your_header.h" // Include the header file where the class and friend declarations are made
    
    
    void CheckIntegerOrReal(const TType *pType1, const TType *pType2) {
        // Implementation of the function
        // You can access private or protected members of the class here using pType1 and pType2
    }
    
    
    void CheckBoolean(const TType *pType1, const TType *pType2) {
        // Implementation of the function
        // You can access private or protected members of the class here using pType1 and pType2
    }
    Last edited by Salem; 09-18-2023 at 08:07 AM. Reason: Spam deleted

  3. #3
    Registered User
    Join Date
    Aug 2023
    Posts
    45
    I did try calling the 2 parameter functions with a NULL 2nd parameter and all is well making the code work. So I guess declaring friends with default parameters might have worked with the older compilers, but not with the newer compiler versions.
    maxcy

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. default values
    By Sasi Krishna in forum C++ Programming
    Replies: 2
    Last Post: 03-14-2016, 11:35 PM
  2. Input showing as default values
    By worl4125 in forum C++ Programming
    Replies: 3
    Last Post: 12-01-2013, 11:27 AM
  3. default values for Struct elements
    By udaraliyanage in forum C Programming
    Replies: 2
    Last Post: 04-09-2011, 06:17 AM
  4. default values in struct
    By taurus in forum C Programming
    Replies: 1
    Last Post: 10-04-2009, 05:43 AM
  5. variable default values
    By dasmann in forum C++ Programming
    Replies: 12
    Last Post: 09-26-2007, 02:21 AM

Tags for this Thread