double link list

Ok my first message on here I hope someone can answer me.

Trying to do a register with char array but can get it working..
Have been googling a lot but can find it.
Is my constructor correct?
1
2
3
4
5
6
7
8
9
10
11
class Register {
    public:
        Register *fram, *bak;
        char titel[maxLength];
        char artist[maxLength];
        Register(Register *f=0, Register *b=0, char t[]=0, char a[]=0)
        : fram(f), bak(b) { strcpy(artist,a),strcpy(titel,t);}
        void lagg_forst(Register *forsta, char a,char t );

    private:
    private:
Last edited on
Is my constructor correct?


No. You give everything a default value of NULL (0) and then assume that they aren't NULL. Register has no fram member.
Is it better now with the fram member?
How should i do it then if want to use it to store artist and a title in the element?
1
2
3
4
5
6
7
8
9
10
11
12
13
Register( Register* f=0, Register* b=0, char* t = 0, char* a=0 )
    : fram(f), bak(b)
{
    if ( t )
        strcpy(titel, t) ;
    else
        titel[0] = '\0' ;

    if ( a )
        strcpy(artist, a) ;
    else
        artist[0] = '\0' ;
}
Thanks!
Topic archived. No new replies allowed.