hai
i am not able to overload a member function of base class in derived
calss.what is the wrong thning i am doing here in the following
program.
# include<iostream>
using namespace std;
class Quad
{
public:
void Area() ;
void Desc() ;
};
class Square : public Quad
{
public:
using Quad:Area;
void Area(int x)
{
cout<<"Area of square is = "<<x*x<<endl;
}
void Desc()
{
cout<<"This Derived class Square from Base Class Quad"<<endl;
}
};
class Rectangle : public Quad
{
public:
using Quad:Area;
void Area(int x, int y)
{
cout<<"Area of Rectangle is = "<<x*y<<endl;
}
void Desc()
{
cout<<"This Derived class Rectangle from Base Class Quad"<<endl;
}
};
class Creator
{
public:
Quad* Creator::Create(int id)
{
if(id==2)
return new Square;
else
return new Rectangle;
}
};
int main(int argc, char* argv[])
{
Creator mcreator;
if (argc<=2)
{
Quad *square=mcreator.Create(argc);
square->Area(3);
square->Desc();
}
else
{
Quad *rectangle=mcreator.Create(argc);
rectangle->Area(3,4);
rectangle->Desc();
}
return 0;
}