10-13-2011, 10:38 PM
Node * myNode = new Node(9); [myNode now has value 9]
The first part of the statement that is on the left of the assignment is declaring a variable pointer (myNode) of type Node. On the right of this statement, the new operator is used to create a new Node object as new Node(9). This is one way in C++ to create objects of classes. The name of the class is provided with the new operator that causes the constructor of the class to be called. The constructor of a class has the same name as the class and as this is a function, parameters can also be passed to it. In this case, the constructor of the Node class is called and '9' is passed to it as an int parameter.
.
The first part of the statement that is on the left of the assignment is declaring a variable pointer (myNode) of type Node. On the right of this statement, the new operator is used to create a new Node object as new Node(9). This is one way in C++ to create objects of classes. The name of the class is provided with the new operator that causes the constructor of the class to be called. The constructor of a class has the same name as the class and as this is a function, parameters can also be passed to it. In this case, the constructor of the Node class is called and '9' is passed to it as an int parameter.
.
0300-9520262
Get solution in 24 hour |cpmputer & internet
mileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
