Thread: Is that operator overloading?

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    84

    Is that operator overloading?

    Hi all,

    what is this part meaning:

    Code:
    ...
    operator _IMQSspServiceBase_FetchedFunction(void) 
    
    throw(OS390_BASE_EX_BASE); 
    ...

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    It's a user-defined conversion operator. It converts a _IMQSsp... to whatever class that function is a member of.
    Code:
    #include <iostream>
    
    class Thing {
        int n;
    public:
        Thing(int x) : n(x) { }
        operator int() { return n; }
    };
    
    int main() {
        Thing th(123);                 // convert int to Thing
        std::cout << int(th) << '\n';  // convert Thing to int
    }

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by algorism View Post
    It converts a _IMQSsp... to whatever class that function is a member of.
    Other way 'round.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by Elkvis View Post
    Other way 'round.
    Oops, you're right of course!

    So it converts the class containing the operator to a _IMQSsp....

  5. #5
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    I'm kind of terrified of an implicit conversion throwing an error O_o

  6. #6
    Registered User
    Join Date
    Nov 2016
    Posts
    84
    Quote Originally Posted by algorism View Post
    Oops, you're right of course!

    So it converts the class containing the operator to a _IMQSsp....
    Ok but what is the utility of such a construct?

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Joe1903 View Post
    Ok but what is the utility of such a construct?
    It allows implicit conversions between unrelated types. Implicit conversion operators can be very dangerous though. If you don't understand why they would be useful, you probably aren't experienced enough to understand when to use them and when not to, and why. Google is a great treasure trove of knowledge on the subject, and I would encourage you to seek out that knowledge. I'd suggest looking up C++ implicit conversion operators, for more info.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  8. #8
    Registered User
    Join Date
    Nov 2016
    Posts
    84
    Quote Originally Posted by algorism View Post
    Oops, you're right of course!

    So it converts the class containing the operator to a _IMQSsp....
    But what is _IMQSspServiceBase_FetchedFunction(void)? I didn`t understand the inline function?

    Code:
    inline 
    
    IMQSspServiceBase::SspFunction:: 
    
    operator _IMQSspServiceBase_FetchedFunction(void) 
    
    throw(OS390_BASE_EX_BASE) 
    
    { 
    
    TC_TRACE_ENTER(OS390_BASE_TRC_GRP, this, "IMQSspServiceBase::" 
    
    "SspFunction::operator _IMQSspServiceBase_FetchedFunction"); 
    
    if (m_fct == 0) 
    
    { 
    
    fetch(); 
    
    } 
    
    TC_TRACE_LEAVE(OS390_BASE_TRC_GRP); 
    
    return(m_fct); 
    
    } 
    
    #endif // ! _IMQ_SSP_SERVICE_BASE_H_ 
    

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    The inline keyword tells the compiler that the function is a candidate for "inlining." This means that the compiler may insert the actual code of the function anywhere the function is called, as an optimization.

    The line:
    Code:
    throw(OS390_BASE_EX_BASE)
    means that the function may throw exceptions of type OS390_BASE_EX_BASE, and only that type. This style of exception specification is deprecated in newer versions of the C++ standard.

    Let's say you have a class called foo. foo implements an implicit conversion operator to int. This would allow the following sort of code to be written:

    Code:
    // assume the definition of class foo as stated
    
    int doSomething(int i)
    {
    // do something with i
    }
    
    int main()
    {
      foo f;
      doSomething(f);
      return 0;
    }
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overloading ++ Operator
    By noobcpp in forum C++ Programming
    Replies: 28
    Last Post: 07-01-2007, 05:22 AM
  2. operator Overloading
    By noobcpp in forum C++ Programming
    Replies: 10
    Last Post: 06-29-2007, 01:22 PM
  3. overloading [] operator
    By Raigne in forum C++ Programming
    Replies: 1
    Last Post: 06-24-2007, 02:44 PM
  4. Overloading -> operator
    By Hunter2 in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2004, 03:08 PM
  5. Operator Overloading...
    By ProgrammingDlux in forum C++ Programming
    Replies: 12
    Last Post: 10-30-2002, 04:29 PM

Tags for this Thread