I have coded a program:
#include<iostream>
using namespace std;
class node
{
public:
node();
node(int i); //constructor,assign i to weight.
....//other members
priavte:
int weight;
};
void main()
{
ma *pnode; //define a pointer pointe to a array of nodes
pnode=new node[4];
for(int i(0);i<4;i++)
{
pnode=node(i); // initiation for the pointer
}
?????//problem here!
}
After some behaviors,I just want to use 3 members of the array--I only want to use pnode[0],pnode[1] and pnode[2],except pnode[3].I wish to delete pnode[3] to recycle one of the memories from the previous behavior "pnode=new node[4]".Just recycle pnode[3],only one element.
How to do that?
The following approaches have been tried,but all failed:
1. delete [] pnode[3];
2. delete pnode[3];
3. ma *tmp=&pnode[3];
delete tmp;
#include<iostream>
using namespace std;
class node
{
public:
node();
node(int i); //constructor,assign i to weight.
....//other members
priavte:
int weight;
};
void main()
{
ma *pnode; //define a pointer pointe to a array of nodes
pnode=new node[4];
for(int i(0);i<4;i++)
{
pnode=node(i); // initiation for the pointer
}
?????//problem here!
}
After some behaviors,I just want to use 3 members of the array--I only want to use pnode[0],pnode[1] and pnode[2],except pnode[3].I wish to delete pnode[3] to recycle one of the memories from the previous behavior "pnode=new node[4]".Just recycle pnode[3],only one element.
How to do that?
The following approaches have been tried,but all failed:
1. delete [] pnode[3];
2. delete pnode[3];
3. ma *tmp=&pnode[3];
delete tmp;