Please explain the following function

This is a discussion on Please explain the following function within the C++ Programming forums, part of the General Programming Boards category; I have come across a function definition starting as: Code: int operator*(vector &y) { body } After putting * just ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    1

    Please explain the following function

    I have come across a function definition starting as:
    Code:
    int operator*(vector &y)
    {
    body
    }
    
    After putting * just after operator and before opening brace of argument what this function means?

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    It means that :
    If you've seen it within a class:
    an object of the class when used as : object * somevector ; will yield an integer. Exactly how it'll happen, depends upon the definition..
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,023
    And if not within a class, it's unary *, meaning it defines the result of *v, for a vector v.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by King Mir View Post
    And if not within a class, it's unary *, meaning it defines the result of *v, for a vector v.
    Thanks for that info. I did not know that operators could be overloaded in that way..
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Explain: A template function is not a function
    By AnishaKaul in forum C++ Programming
    Replies: 2
    Last Post: 05-13-2010, 10:58 AM
  2. trim function - could you explain please
    By c_lady in forum C Programming
    Replies: 17
    Last Post: 03-27-2010, 09:19 AM
  3. Can someone explain to me what this function is doing?
    By mr_coffee in forum C Programming
    Replies: 7
    Last Post: 09-05-2008, 12:18 PM
  4. plz explain a small function
    By samirself in forum C Programming
    Replies: 4
    Last Post: 11-11-2004, 09:14 AM
  5. can anyone explain the gets() function?
    By Ryan_P in forum C++ Programming
    Replies: 5
    Last Post: 05-18-2002, 01:17 PM

Tags for this Thread


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