DYNAMIC CONSTRUCTORS
The dynamic constructor can used
to allocate memory while creating objects. This will enable the system to
allocate the right amount of memory for each object when the objects donot follow
the same size. Thus resulting in the saving of memory. The allocation of memory
for the objects at the time of their constructor is called dynamic constructor.
EXAMPLE:
class
String
{
char *S;
public:
String(char*s)
{
int l=strlen(s);
this->s=newchar[l+i];
strcpy(this ->s,s);
}
void put( )
{
cout<<”string=”<< x <<endl;
}
};
void
main( )
{
clrscr( );
String obj(“
OBJECT ORIENTED PROGRAMMING LANGUAGE”);
obj.put( )
}
No comments:
Post a Comment