not finding the class.

Trying to do some basic inheritance and I'm getting this error:
 
/home/rej3kt/Desktop/C++ Class/custclass/cust.h|13|error: expected class-name before ‘{’ token|


This is what I've done it like:
1
2
class Customer : public Human
{};


all my info is in the brackets obviously
Did you define class Human?
yeah just wrote this in human.cpp

1
2
3
4
5
6
7
8
9
10
11
class Human
{
    public:

    void setID(int identity);
    int getID();

    private:
    int identity;
};
Class declarations should go into header files (.h), with an include guard:

human.h:
1
2
3
4
5
6
7
8
#ifndef HUMAN_H
#define HUMAN_H

class Human {
    // ...
};

#endif 

customer.h:
1
2
3
4
5
6
7
8
9
10
#ifndef CUSTOMER_H
#define CUSTOMER_H

#include "human.h"

class Customer : public Human {
    // ...
};

#endif 
Last edited on
Sorry mate I meant to say it was my .h file not cpp.

My class already has the guards. Just didn't include them because I didn't know they were important.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef HUMAN_H_INCLUDED
#define HUMAN_H_INCLUDED



#endif // HUMAN_H_INCLUDED


class Human
{
    public:

    void setID(int identity);
    int getID();

    private:
    int identity;
};
The declaration should be between the #define and the #endif directives. Otherwise the include guard is useless. Could you post the entire customer.h file?
Bare in mind that this is fine and works without ": public Human"

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
#ifndef RANDOMCLASSHEADER_H_INCLUDED
#define RANDOMCLASSHEADER_H_INCLUDED



#endif // RANDOMCLASSHEADER_H_INCLUDED





class Customer : public Human
{

    Customer();

 public:
    Customer(char name[], char gender[], int phone, char pcode[], float dob);

    void setName(char name[]);
    char* getName();

    void setGender(char get[]);
    char* getGender();

    void setPhone(int phone);
    int getPhone();

    void setPcode(char pcode[]);
    char* getPcode();

    void setDob(float dob);
    float getDob();


 private:
    char cust_name[50];
    char cust_gender[50];
    int cust_phone;
    char cust_pcode[50];
    float cust_dob;
};
Well, you're not including human.h. Look at my examples up there. And remember to fix the include guards.
What declaration are you talking about, the Class Customer : public Human should be in the middle of
1
2
#ifndef RANDOMCLASSHEADER_H_INCLUDED
#define RANDOMCLASSHEADER_H_INCLUDED  
? And your saying that I need to include
1
2
3
4
5
6
#ifndef HUMAN_H_INCLUDED
#define HUMAN_H_INCLUDED



#endif // HUMAN_H_INCLUDED 


into the customer.h file?
Use my examples above as a start, then copy whatever is between the curly braces for each class into the place I filled with a comment (// ... ). Pay attention to the names of the files.

EDIT: I'm saying you need to #include "human.h"
Last edited on
Ty mate, got it compiling now, I'll figure out something to use in main to double check its working later. Thanks alot :). Better go read up about "guards" now.
Topic archived. No new replies allowed.