Dynamic initialization of objects and dynamic constructor, C/C++ Programming

Dynamic Initialization of objects:

It is initializing the objects by passing the valued to the constructor from the user input or

other means.   Through cin operator a value can be stored in a variable and passed through a constructor this form of initializing an object is known dynamic initialization.

Dynamic Constructor:

The memory allocation for a constructor can be managed using new operator called new,

similarly the memory can be free with another operator called deleter.


class dynmem

{ char *name;

int length;



{length =0;

name = new char[length+1];


dynmem(char *s)

{length = strlen(s);

name = new char[length+1];//for null terminator



void display(void)



void join(dynmem &a, dynmem &b);


void dynmem::join(dynmem &a, dynmem &b)

{length = a.length+b.length;

delete name;

name = new char[length+1]; strcpy(name,a.name); strcat(name,b.name);


void main()



char *first="Electronic ";

dynmem name1(first);

dynmem name2("and Communication ");

dynmem name3("Engineering"); dynmem s1,s2; s1.join(name1,name2); s2.join(s1,name3); name1.display();

name2.display(); name3.display(); s1.display(); s2.display();


Posted Date: 9/20/2012 8:12:31 AM | Location : United States

Related Discussions:- Dynamic initialization of objects and dynamic constructor, Assignment Help, Ask Question on Dynamic initialization of objects and dynamic constructor, Get Answer, Expert's Help, Dynamic initialization of objects and dynamic constructor Discussions

Write discussion on Dynamic initialization of objects and dynamic constructor
Your posts are moderated
Related Questions
(a) Pairs may be represented using a lambda. Using only lambdas, create a procedure (triple x y z) that constructs a triplet. You may NOT use car, cons or cdr in the triplet proced

creating a system having five process from p0 to p4 and five resource types. create the need matrix use the safe algorithm to test if the system is in safe mode.

how can I write a c++ program that generate all evn numbers less than 1000?

Sir i want to know all the basic knowledge of turbo c.

Define the Meaning of Call by reference? In "call-by- reference", as an alternative of passing the value of a variable, the location number (or the address) of the variable is

C Program for FUNCTION OF COUNT THE INTEREST float si(float,float,float); void main() {           float p=0,r=0,n=0,k=0;           clrscr();           printf("E

need some help with finishing a program

How would I use variables of a C++ object within a Lua function, and then call the Lua function from C++ code?

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

The program must use the file named on the command line as its input file. Suppose the program is named pdbtool. Then if the user types pdbtool 1A36.pdb the program must read the d