class problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Steinicke

    class problem

    Hello ng,

    i have the following (object orientated) problem:

    i have 2 classes, "Class1" and "Class2".
    Now "Class1" calls a function "func" of the "Class2".

    Is it possible to know out of the "Class2", which class called the
    function "func" ?

    And how do you realise this ?

    Thanks and best regards, frank


  • Ron Natalie

    #2
    Re: class problem


    "Frank Steinicke" <steinicke@web. de> wrote in message news:bk7664$slu $1@redenix.uni-muenster.de...[color=blue]
    >
    > Is it possible to know out of the "Class2", which class called the
    > function "func" ?[/color]

    No. C++ functions (member or otherwise) have no
    inate idea of how they were called.
    [color=blue]
    > And how do you realise this ?[/color]

    You need to pass in what ever information the called function needs
    as an argument.


    Comment

    • Buster Copley

      #3
      Re: class problem

      Frank Steinicke wrote:[color=blue]
      > i have the following (object orientated) problem:
      >
      > i have 2 classes, "Class1" and "Class2".
      > Now "Class1" calls a function "func" of the "Class2".
      >
      > Is it possible to know out of the "Class2", which class called the
      > function "func" ?
      >
      > And how do you realise this ?[/color]

      This reminds me of Borland's VCL, where functions used as event
      callbacks have 'TObject * Sender' as their first parameter. These
      functions then know from which object they were called. To get
      the class would typically require RTTI.

      I don't know if this is any help to you. Good luck.

      Regards,
      Buster.

      Comment

      • Mr E Mann

        #4
        Re: class problem

        Pass a reference to Class1 into Class2 when you instantiate Class2.
        Otherwise, the answer to your question is no.

        Comment

        Working...