Thread: Figure out how method was called?

  1. #1
    Registered User
    Join Date
    Jul 2007

    Figure out how method was called?

    Is there a way to figure out whether a method was called internally (from another method in the file) or externally (from another file)? Or alternatively, whether or not a method will return to an internal call or an external one?

    Obviously I could add some fake boolean parameter to my methods and just send true or false depending upon where I call it but if I'm fixed with certain method structures I can't do that.
    Last edited by jcafaro10; 02-06-2009 at 04:20 PM.

  2. #2
    The larch
    Join Date
    May 2006
    Why do you want to know? Shouldn't a method always do the same thing, given the same input (unless it is meant to do somewhat random things, or get user input or the like), and not care where it was called from?

    Otherwise, wouldn't that be something the debugger can tell you (if you need it for debugging)?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    I'm with Anon.

    If you need to do different things when you are calling from another member function, then you should have two private/protected functions and one public function which calls one form of the private function, and the "from within the class" calls the other private function (which may then call the first private function if it makes sense, after or before it does the "internal call only" part).

    Edit: By making functions private you can ensure that they are not being called from outside of the class itself - so only member or friend functions can use that function.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stuck on display method
    By shintaro in forum C++ Programming
    Replies: 2
    Last Post: 02-01-2009, 05:17 PM
  2. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-08-2008, 12:30 AM
  3. Static templated method problem
    By mikahell in forum C++ Programming
    Replies: 6
    Last Post: 11-19-2006, 09:19 AM
  4. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM