Which print function going to be called. scope question.

S

sasha

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top