Request for member which is of non-class type 'char'.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class docnur
{
    char name[40];
    int age;
    char gender[10];
    unsigned long long phoneno;
    int exp;
    char dept[40];
    float salary;
    char dn;
public:
    int dnid;
    void dadd();
}dn;
void docnur::dadd()
{     
        cout<<"\nEnter staff ID:";                    cin>>dnid;
        cin.get(ch);
        cout<<"\nEnter name of the staff member:";           cin.getline(name, 40);
        cout<<"\nEnter age of the staff member:";            cin>>age;
        cin.get(ch);
        cout<<"\nGender of staff member:";                   cin.getline(gender, 10);
        cout<<"\nEnter address:";
        cout<<"\n\tStreet:";                            cin.getline(ad.addr, 60);
        cout<<"\n\tDistrict:";                          cin.getline(ad.district, 60);
        cout<<"\n\tState:";                             cin.getline(ad.state, 30);
        cout<<"\n\tCountry:";                           cin.getline(ad.country, 20);
        cout<<"\nEnter phone number:";                  cin>>phoneno;
        cin.get(ch);
        cout<<"\nEnter experience:";                    cin>>exp;
        cin.get(ch);
        cout<<"\nEnter department:";                    cin.getline(dept, 40);
        cout<<"\nEnter salary:";                        cin>>salary;
        label: 
            cout<<"\nEnter job: \n\t1. Press 'n' for nusrse. \n\t2. Press 'd' for doctor.";
            cin>>ch;
            switch (ch)
            {
                case 'n': dn='n';
                        break;
                case 'd': dn='d';
                        break;
                default:cout<<"\nWrong Choice! \nEnter Again!!";
                        goto label;
                        break;
            }
        ofstream fout;
        fout.open("Staff.txt", ios::app);
        fout.write((char *)&dn, sizeof(dn));
        fout.close();
        cout<<"\nRecord added to file.";
        cout<<"\nWant to add more staff records?";
        cin>>c;
        cin.get(ch);
        if (c=='y'||c=='Y')                                 dn.dadd();
        else
        {
            cout<<"\n\n";
            for (int A=0; A<30; A++)
                cout<<"-";
            cout<<"Going back to staff menu!";
            for (int A=0; A<30; A++)
                cout<<"-";
            DAT();
        }
}


It gives the error when compiled saying dn.dadd() is invalid call. Idk what is wrong? Please help!!!
What you've posted is not sufficient to compile your program.
@AbstractionAnon I know! But even if I call dadd function from main, it doesn't work!
Please help me out here!
Last edited on
If you're not going to post enough code to compile your program, then I am very limited in what I can comment on.

Line 14: Why is dn global? Globals should be avoided.

Line 24-27: You're referencing some kind of address structure, but you haven't shown a declaration for such an address structure. docnur certainly does not contain this address structure. Hopefully, you haven't declared this as a global variable also.

Line 18,21,29,31: Where is ch declared? It should be a local variable within docnur:dadd().

Line 44: gotos should be avoided. Use a loop.



Request for member which is of non-class type 'char'.


line 10: docnur has a char data member called dn
line 14: an object called dn is instantiated
line 55: the dadd function is called within itself dn.dadd();

It sounds like there's confusion with the same name being used for different things and dadd() is trying to be called on the char variable, which is not valid.

Last edited on
Ohhh
Alright
Now I see where I was going wrong!!!!
Thanks a lot @wildblue
Topic archived. No new replies allowed.