#ifndef

What is wrong with the following lines of code?
the header file is called: vergelijking.h
1
2
3
#ifdef VERGELIJKING_H_
#define VERGELIJKING_H_
#endif 

You're putting #ifdef not #ifndef
So if VERGELIJKING_H_ is defined, you're defining it again.

I think you can use
1
2
3
#pragma once

// Header code 

which should yield faster compile times. It won't be noticeable in small projects.

You can even combine the two:

1
2
3
4
5
#pragma once
#ifndef _MYHEADER_H_
#define_MYHEADER_H_
// Header code
#endif 
Last edited on
it doesn't works too
What doesn't? I told you three things:
#pragma once
#if
and combining the two.

What are you trying to do? Let me see the full header code.
ok, here you are:
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
92
93
94
95
96
97
98
99
100
101
102
#pragma once
#ifndef VERGELIJKING_H_
#define VERGELIJKING_H_


//#include "handige_functies.h"

class berekening{
      protected:
              float beginmaat, eindmaat, uitkomst;//ok
              char maten[15][15];//ok
              float *eenheden;//ok
              int aantalp;//ok
      public:
              bool checken(char *cbegin, char *ceind);//ok
              void berekenen(float beginhoeveel);//de uitkomst berekenen: ok
              float getuitkomst();//de uitkomst returnen :ok
              };//end class



//______________________________________________________________________________
void berekening::berekenen(float beginhoeveel)
{
     //berekenen
     uitkomst = (beginmaat / eindmaat) * beginhoeveel;
}//end function
//______________________________________________________________________________
float berekening::getuitkomst()
{
      return uitkomst;
}
//______________________________________________________________________________
bool berekening::checken(char *cbegin, char *ceind)
{
     int count=0;
     bool check=false, beind=false, bbegin=false;
     for(count=0; count<aantalp; count++)
     {
          if(strcmp(cbegin, maten[count])==0)
          {
               bbegin=true;
               beginmaat=eenheden[count];
          }//end if
          else{bbegin=false;}
          if(strcmp(ceind, maten[count])==0)
          {
               beind=true;
               eindmaat=eenheden[count];
          }
          else{beind=false;}//end if
     }//next count

     if(bbegin==true && beind==true)
     {
          check=true;
     }
     return check;
}//end function
/*______________________________________________________________________________
________________________________________________________________________________
______________________________________________________________________________*/
class Lengte: public berekening{
      public:
              Lengte();//constructor
              };//end class

Lengte::Lengte()
{
     strcpy(maten[0],"mm");
     strcpy(maten[1],"cm");
     strcpy(maten[2],"inch");
     strcpy(maten[3],"dm");
     strcpy(maten[4],"chain");
     strcpy(maten[5],"foot");
     strcpy(maten[6],"yard");
     strcpy(maten[7],"m");
     strcpy(maten[8],"dam");
     strcpy(maten[9],"hm");
     strcpy(maten[10],"km");
     strcpy(maten[11],"mile");

     eenheden=new float[12];
     eenheden[0]=0.001;
     eenheden[1]=0.01;
     eenheden[2]=0.0254;
     eenheden[3]=0.1;
     eenheden[4]=0.201168;
     eenheden[5]=0.3048;
     eenheden[6]=9144;
     eenheden[7]=1;
     eenheden[8]=10;
     eenheden[9]=100;
     eenheden[10]=1000;
     eenheden[11]=1609.344;

     aantalp=11;
     beginmaat=0;
     eindmaat=0;
     uitkomst=0;
}//end constructor
#endif 

What exactly is the point of using both #pragma one and inclusion guards?
who are you asking?
I see no reason why the preprocessor includes are not working.

It does not work for me, either...

I didn't say there was a point in doing it, I was saying it was possible.

I think the point is because it's faster on some compilers to use #pragma once. But then that would be lost because you're using #endif anyway... I'm not sure.
Last edited on
who are you asking?
It's an open semi-rhetorical question.

I was saying it was possible
It's also possible to assign something to itself. It doesn't mean there's a point to it.
My point was that there may not be a point to it.
Mine was that whether something is possible or not is irrelevant if there's no point in doing it.
Ok, then.

Any idea on the problem itself, because I have none :(
OP is doing it wrong.
With #pragma once, if a file gets included a lot of times, it is only processed once.
With #ifndef ..., the file would have to be loaded and processed each time it is included.

#pragma once is an MS thing, so the backup #ifndef ... is recommended if you are sharing.
@hannes

You must split your file into two separate files.

vergelijking.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once
#ifndef VERGELIJKING_H_
#define VERGELIJKING_H_

class berekening{
      protected:
              float beginmaat, eindmaat, uitkomst;//ok
              char maten[15][15];//ok
              float *eenheden;//ok
              int aantalp;//ok
      public:
              bool checken(char *cbegin, char *ceind);//ok
              void berekenen(float beginhoeveel);//de uitkomst berekenen: ok
              float getuitkomst();//de uitkomst returnen :ok
};//end class

//______________________________________________________________________________
class Lengte: public berekening{
      public:
              Lengte();//constructor
};//end class

#endif 

vergelijking.cpp
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
#include "vergelijking.hpp"

//______________________________________________________________________________
void berekening::berekenen(float beginhoeveel)
{
     //berekenen
     uitkomst = (beginmaat / eindmaat) * beginhoeveel;
}//end function
//______________________________________________________________________________
float berekening::getuitkomst()
{
      return uitkomst;
}
//______________________________________________________________________________
bool berekening::checken(char *cbegin, char *ceind)
{
     int count=0;
     bool check=false, beind=false, bbegin=false;
     for(count=0; count<aantalp; count++)
     {
          if(strcmp(cbegin, maten[count])==0)
          {
               bbegin=true;
               beginmaat=eenheden[count];
          }//end if
          else{bbegin=false;}
          if(strcmp(ceind, maten[count])==0)
          {
               beind=true;
               eindmaat=eenheden[count];
          }
          else{beind=false;}//end if
     }//next count

     if(bbegin==true && beind==true)
     {
          check=true;
     }
     return check;
}//end function
/*______________________________________________________________________________
________________________________________________________________________________
______________________________________________________________________________*/
Lengte::Lengte()
{
     strcpy(maten[0],"mm");
     strcpy(maten[1],"cm");
     strcpy(maten[2],"inch");
     strcpy(maten[3],"dm");
     strcpy(maten[4],"chain");
     strcpy(maten[5],"foot");
     strcpy(maten[6],"yard");
     strcpy(maten[7],"m");
     strcpy(maten[8],"dam");
     strcpy(maten[9],"hm");
     strcpy(maten[10],"km");
     strcpy(maten[11],"mile");

     eenheden=new float[12];
     eenheden[0]=0.001;
     eenheden[1]=0.01;
     eenheden[2]=0.0254;
     eenheden[3]=0.1;
     eenheden[4]=0.201168;
     eenheden[5]=0.3048;
     eenheden[6]=9144;
     eenheden[7]=1;
     eenheden[8]=10;
     eenheden[9]=100;
     eenheden[10]=1000;
     eenheden[11]=1609.344;

     aantalp=11;
     beginmaat=0;
     eindmaat=0;
     uitkomst=0;
}//end constructor 

Good luck!
Last edited on
it was a fault with my environment. anyway, many thanks!
Topic archived. No new replies allowed.