Hi Paul,
         Thankls for your response. But my query is
not related to using base class member function. I
think I didn't keep proper question. My question is
related to operator overloading. When we over load an
operator in base class , can that function be used
with derived class object as we norammly we base class
functions with derived class objects <=> we inherited
with public access specifier. Hope I kept the question
in proper way.


Thanks&Regards,
Gopi.k
--- Paul Herring <[EMAIL PROTECTED]> wrote:

> On 2/14/07, Gopi Krishna Komanduri
> <[EMAIL PROTECTED]> wrote:
> 
> > 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..
> 
> You need to use scope resolution - look for
> base::show() and base::x
> in derived in the following example and see if it
> covers what you're
> after?
> 
> #include <iostream>
> #include <string>
> 
> class base{
> protected:
>     int x , y;
> public:
>     base(int _x=10, int _y=20): x(_x), y(_y) {}
>     virtual void show(std::string s){
>         std::cout << s << "(base::)x=" << x <<"
> (base::)y=" << y << std::endl;
>     }
> 
> };
> class derived:public base{
>     int x , y;
> public:
>     derived(int _x=50, int _y=60): x(_x), y(_y) {}
>         virtual void show(std::string s){
>                 base::show(s);
>         std::cout << s << "base::x=" << base::x <<"
> base::y=" <<
> base::y << std::endl;
>         std::cout << s << "(derived::)x=" << x <<"
> (derived::)y=" << y
> << std::endl;
>         }
> };
> 
> int main(){
>         base b, *pb;
>         derived d;
> 
>         pb = new derived;
> 
>         b.show("b.show() ");
>         std::cout << std::endl;
> 
>         pb->show("pb->show() ");
>         std::cout << std::endl;
> 
>         d.show("d.show() ");
>         std::cout << std::endl;
> 
>         return 0;
> }
> 
> 
> Output:
> 
> b.show() (base::)x=10 (base::)y=20
> 
> pb->show() (base::)x=10 (base::)y=20
> pb->show() base::x=10 base::y=20
> pb->show() (derived::)x=50 (derived::)y=60
> 
> d.show() (base::)x=10 (base::)y=20
> d.show() base::x=10 base::y=20
> d.show() (derived::)x=50 (derived::)y=60
> 
> -- 
> PJH
> Aio, quantitas magna frumentorum est
> 



 
____________________________________________________________________________________
Need a quick answer? Get one in minutes from people who know.
Ask your question on www.Answers.yahoo.com

Reply via email to