SPONSORS:






User Tag List

Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Jun 2001
    Location
    Bedford, MA, USA
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Want to call a function from within a method where name is the same

    Is there any way I can call a function from within a method where the function I'm calling is the same name as the method I'm calling from? I know I can rename one or the other, but it's just that I like the name.

    code:
    ---------------------------------------------
    winclass SystemOps
    {
    string GetMatchingLineFromFile(string sPath, string sPattern)
    return GetMatchingLineFromFile(string sPath, string sPattern)
    }
    ---------------------------------------------
    I think I know the answer [NO], but I thought I'd ask anyway.

    Thanks,
    - Jim




    ------------------

  2. #2
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Want to call a function from within a method where name is the same

    Well believe it or not, there is. I just found it through experimentation.


    John


    ------------------

  3. #3
    Member
    Join Date
    Jun 2001
    Location
    Bedford, MA, USA
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Want to call a function from within a method where name is the same

    Cool!

    The only potential problem is if a method named my_func exists in the parent class or above, it will be called instead of the function. Correct?

    - Jim

    ------------------

  4. #4
    Junior Member
    Join Date
    Jan 2003
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Want to call a function from within a method where name is the same

    Actually, it's not even that complicated, as methods and functions are similar, although different things. A method is parented to a window object or class of window, while a function stands alone. Therefore, the way you call the method/fucntion determines which one SilkTest will use during the run. For Example:

    Assume you have a metod named ClickThis() and a function named ClickThis().

    object.ClickThis() - calls the method
    ClickThis() - calls the fucntion.

    Although you can do this, I wouldn't recomend having a function and a method use the same name. It will make it more difficult for someone else to troubleshoot your code.


    ------------------


    [This message has been edited by xmako (edited 03-14-2003).]

  5. #5
    Super Member
    Join Date
    Jul 2001
    Location
    Earth
    Posts
    1,882
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Want to call a function from within a method where name is the same

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by xmako:
    Actually, it's not even that complicated, as methods and functions are similar, although different things. A method is parented to a window object or class of window, while a function stands alone. <HR></BLOCKQUOTE>

    Except in the case that is quoted by Jim... If you call a function from a method, the calling order will be to always look inside the current object to find a method or function first.

    ------------------
    James Soderborg
    http://www.ameliortech.com
    jamesso@ameliortech.com

  6. #6
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Want to call a function from within a method where name is the same

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Jim Griffiths:
    The only potential problem is if a method named my_func exists in the parent class or above, it will be called instead of the function. Correct?
    <HR></BLOCKQUOTE>
    No I don't think so. I believe that the "::" essentially translates the call to being a function that is not related to ANY instance.

    To call the parent's version of the method you'd instead use:

    derived::my_func()

    or

    [class_name]::my_func()

    To recursively call 'this' instance's method you'd use:

    this.my_func() or just my_func().


    John


    ------------------

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 02:35 AM.

Copyright BetaSoft Inc.