1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problem in c++

Discussion in 'C++' started by sdmahapatra, Jul 20, 2009.

  1. sdmahapatra

    sdmahapatra New Member

    Joined:
    Jun 16, 2009
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    I have a function under Base class and at the definition tine of this base class function I need to call another function which is define under the Derived class. how to do this??
    My class declaration is below
    Code:
    class Base{
       
      public:
       
      void showdata(double);
       
      };
       
      class Derived : public Base{
       
      public:
                      inline double F(double x)
      {
                      return exp(-x) + x*x;
      }
    Define the function below :

    Code:
    void Base::showdata(double a)
      {
                      std::cout<<"The value of the Function : " << F(a);
      }
      
    and the main function :
    Code:
    int main()
      {
      //Base obj;
      Derived obj;
      obj.F(1.0);
      return 0;
      }
    I'm getting an error :
    I know this is a correct error but I need to call a derived class function into the base class function.Is it possible any how?? or I have to go different way like template etc
    So how to solve this problem.
    With Warm Regards
    sdmahapatra
     
    Last edited: Jul 20, 2009

Share This Page