object struggle

hi all
I was wonderring how can I delete an object array.
i tried delete[]b ; or something simillar to that but i can t get it to work.. please help. thx. :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
struct x
{
    char[20] name;
    int[20] year;
.
.
.
.
. 
};
class book
{
     x y;
   public:.
          .
          .
          .
            void newbook()
           void remove()
}
void book::newbook()
{
    cout << "name";
    cin>> y.name;
.
.
.
.

}

int main()
{
int i = 0;
book *b = new book[50];
{in the loop
b[i].newbook()    // this is in some kind of loop.. i ve got that 
i++               //when you press that you add new book and so on.
}
b[4].remove();    // how do i remove for example 4th book of this object array


}
1
2
char[20] name;
int[20] year;

should be:
1
2
char name[ 20 ];
int year[ 20 ];


You cannot remove an element from a c-style array. Have a look at std::vector, that might suit your needs better: http://www.cplusplus.com/reference/vector/vector/
Last edited on
ok thank you.. I hoped that i can remove it, but oh well.. i guess vector will do it.
Topic archived. No new replies allowed.