Hi Paul,
             The following below is the code I have used.
  // OperatorOverLoadingInher.cpp : Defines the entry point for the console 
application.
  //
  
  #include "stdafx.h"
  class base1
  {
      int x , y;
  public:
      base1()
      {
          x=10;
          y=20;
      }
      base1 operator + (base1 *obj)
      {
          this->x=obj->x+this->x;
          this->y=obj->y+this->y;
          return *this;
      }
      virtual void show()
      {
          cout<<x<<y;
      }
  };
  class derived:public base1
  {
      int x,y;
  public:
      derived():base1()
      {
          x=50;
          y=60;
      }
      void show1()
      {
          cout<<x<<y;
      }
  };
  
  Now My doubt is as I have used Public inheritence , then I can use base  
class public member functions with derived class object. At the same  time I 
should use the operator which I overloaded in base class in  derived class. But 
I am unable to use it. Could you please explain why  it happens so..

Paul Herring <[EMAIL PROTECTED]> wrote:                                         
         On 2/14/07, Gopi Krishna Komanduri <[EMAIL PROTECTED]> wrote:
  >
  >    Hi Frnds,
  >                  Why overloaded operator won't work for derived calss when 
we supply
  > operator overloading method in base class and also we derived using  
public. Can any
  > one of you please suggest.
  
  Can you supply code to demonstrate what you're trying to do? Your
  explanation isn't too clear:
  
  #include <iostream>
  
  class base {
  public:
     void foo(){ std::cout << "base::foo()\n"; }
     virtual void bar() { std::cout << "base::bar()\n"; }
  };
  
  class derived : public base {
  public:
     void foo(){ std::cout << "derived::foo()\n"; }
     virtual void bar() { std::cout << "derived::bar()\n"; }
  };
  
  int main(){
     base* b;
     b = new derived;
  
  b->foo(); // base::foo() expected - what you're seeing?
     b->bar(); // derived::bar() expected - what you want?
  
  return 0;
  }
  
  -- 
  PJH
  Aio, quantitas magna frumentorum est
  
      
                                    

 
---------------------------------
Want to start your own business? Learn how on Yahoo! Small Business.

Reply via email to