Thread: Please explain the following function

  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
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    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..

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    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
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    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..

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, 10: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