public function calls

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

    public function calls

    I want to know the difference between the following 3 methods of
    calling a public function, which method is better and why

    method 1:

    myClass::myFunc tion();


    method 2:
    myClass myObject;
    myObject.myFunc tion();

    method 3:
    myClass * pMyObject;
    pMyObject->myFunction() ;

    I know the difference between 2 and 3, but i'd like to know the
    differences between 1 and the others

    BlueDoze
  • Julián Albo

    #2
    Re: public function calls

    BlueDoze escribió:
    [color=blue]
    > method 1:
    >
    > myClass::myFunc tion();[/color]

    You call this way when myFunction is a static member function of
    myClass.

    Regards.

    Comment

    • .oO LGV Oo.

      #3
      Re: public function calls

      > method 3:[color=blue]
      > myClass * pMyObject;
      > pMyObject->myFunction() ;[/color]

      and method 3 is generally used for polymorphism ; if pMyObject points to a
      derived class of myClass and if myClass declares virtual functions, then you
      get polymorphism


      Comment

      • jeffc

        #4
        Re: public function calls


        "BlueDoze" <bluedoze@yahoo .com> wrote in message
        news:a53ecee3.0 311020306.2054e e9f@posting.goo gle.com...[color=blue]
        > I want to know the difference between the following 3 methods of
        > calling a public function, which method is better and why
        >
        > method 1:
        >
        > myClass::myFunc tion();
        >
        >
        > method 2:
        > myClass myObject;
        > myObject.myFunc tion();
        >
        > method 3:
        > myClass * pMyObject;
        > pMyObject->myFunction() ;
        >
        > I know the difference between 2 and 3, but i'd like to know the
        > differences between 1 and the others[/color]

        Method 1 would be used in 3 cases:
        a) myFunction is a static function, being called from somewhere outside
        myClass
        b) it's a function of the base class, where it's being called from a derived
        class of myClass
        c) it's a member function being called from another function of myClass.

        In the case of c) it's not necessary to prefix with myClass - in fact it
        would be redundant and confusing.


        Comment

        Working...