using a class inside another class

Probably a noob mistake, but I do not find why my compiler gives me the following error :

error: ‘sleep’ does not name a type

in this code :

1
2
3
4
5
6
7
8
9
10
#include "sleep.h"

class HMC5883L
{
   private:
      sleep sl ;
      
      
   public:
} ;


(I removed most of the code to understand my code better...)

Why doesn't he know my class "sleep"?
I included it on top of this header file.

full header files :
sleep.h
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
/*
 * This class will make use of the nanosleep() function.
 * Just to make my original code a little bit smaller...
 *
 * Usage :
 *
 * #include "sleep.h"
 *
 * sleep sl ;
 * sl.sleepSec(0.1) // wait 0.1 sec
 * sl.sleepNanoSec(100000000) ; // wait 0.1 sec
 *
 * The function returns a 0 if it failed, 1 if succeeded
 */

/* 
 * File:   sleep.h
 * Author: Steven Noppe
 *
 * Created on 5 februari 2017, 10:03
 */

#ifndef SLEEP_H
#define SLEEP_H

#include <time.h>

class sleep
{
	private:
		timespec waitTime ;
				
		float hours ;
		float minutes ;
		float seconds ;
		float milliseconds ;
		float microseconds ;
		long int nanoseconds ;
		
		void resetAll() ;
		
	public:
		sleep() ;
		int sleepSec(float s) ;
		int sleepNanoSec(long int nanoS) ;
		int sleepMicroSec(float microS) ;
		int sleepMilliSec(float milliS) ;
};
#endif /* SLEEP_H */ 


hmc5883L.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef HMC5883L_H
#define HMC5883L_H

#include <linux/i2c-dev.h>	// for the ioctl() function
#include <cmath>			// for some math functions
#include <unistd.h>			// for the read() and write() function
#include <fcntl.h>			// for the open() function
#include <cstdlib>			// for the exit() function
#include <fstream>			// for some streaming functions...
#include <sstream>			// for using string streams	
#include <string.h>			// for manipulating strings
#include <iomanip>			// for setw() and setfill() functions

#include "sleep.h"

/*
 * Compiling with GCC, gives a fault because M_PI is not defined
 * With an IDE like Netbeans, we do not have that problem
 * Thats why we define it here
 */
#ifndef M_PI
	#define M_PI 3.14159265358979323846
#endif

/*
 * Same problem here with GCC, it seems he doesn't know what 'true' is 
 */
#ifndef true
	#define true 1
#endif

using namespace std;

class HMC5883L
{
	private:
		sleep sl ;
		
		short x ;
		short y ;
		short z ;
		short xOffset ;
		short yOffset ;
		
		float angle ;
		float declinationDegree ;
		float declinationMinutes ;
		
		int fd ;	// 'fd' stands for 'file descriptor'
		unsigned char buf[16] ;
		
	public:
		HMC5883L(short xO, short yO, float declDegree, float declMinutes) ;
		
		short getX() 
		{
			return x ;
		}
		
		short getY() 
		{
			return y ;
		}
		
		short getZ()
		{
			return z ;
		}
		
		void setXOffset(short xO)
		{
			xOffset = xO ;
		}
		
		void setYOffset(short yO)
		{
			yOffset = yO ;
		}
		
		float getAngle()
		{
			return angle ;
		}
		
		void updateData() ;
		
		void calibrateHMC5883L() ;
		
		void calibrateHMC5883L(int xOffs, int yOffs) ;
} ;
#endif /* HMC5883L_H */ 
Looks like you have a name clash with the POSIX sleep function.

http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html
Topic archived. No new replies allowed.