Which print function going to be called. scope question.

Discussion in 'C++' started by sasha, Apr 15, 2008.

  1. sasha

    sasha Guest

    class Base{

    public:
    std::eek:stream& operator<<( std::eek:stream& os, const string &str )
    { return print(os); }

    void print(std:eek:stream& os){ os<<"Base\n";}
    };


    class Derived{
    public:
    using Base::eek:perator<<;
    void print(std:eek:stream& os){ os<<"Derived\n";}
    };

    D d=Derived;
    D<<"str";

    B & pd=new Derived;
    pd<<"str";


    Notice that that print is not a virtual function.

    I wonder if you bring base class member in the Derive class scope
    and invoke it via Derived object, which print is it going to call: one
    from derived or one from base.
     
    sasha, Apr 15, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Sullivan
    Replies:
    0
    Views:
    277
    Mark Sullivan
    Dec 21, 2007
  2. Mark Sullivan
    Replies:
    0
    Views:
    284
    Mark Sullivan
    Dec 21, 2007
  3. Esmail
    Replies:
    4
    Views:
    327
    Esmail
    May 1, 2009
  4. Esmail
    Replies:
    2
    Views:
    293
    Esmail
    May 1, 2009
  5. Andrew Falanga
    Replies:
    2
    Views:
    217
    Andrew Falanga
    Nov 22, 2008
Loading...

Share This Page