bh**********@gmail.com wrote:
Hi
I have a rather simple question:
I have following class definitions:
class Base
{
public:
virtual void display ()
{
cout << "Base";
Error: cout is undefined. You need to #include <iostreamand get cout into
the global namespace with: using std::cout;
}
};
class Derived:public Base
{
public:
virtual void display ()
{
cout << "Derived";
Error (same as above).
}
};
void main ()
Error: main() must always return int.
{
Base *ptr = new derived;
Error: derived is undefined. You probably meant Derived.
ptr->display ();
}
When I compile this code in VC++ 6.0 it works fine.
That's strange. Though VC++ 6.0 is not really known for good standard
compliance, I thought it'd at least correctly implement the
case-sensitivity of C++. Are you sure it's really this code you tried?
My question is that can this code work always?
Actually, it shouldn't ever due to several errors in the code.
Or the "virtual void display ()" in derived class can create problem?
I don't see a reason why it should. What makes you think so?
What can be the problem with this code?
See above.