cannot convert bool to BOOL

Why am i getting these same two errors on lines 66 and 90. cannot convert bool to BOOL in return?

thanks.

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
103
  #include <iostream>

enum LEVEL { NONE,LOW,MEDIUM,HIGH };

enum BOOL { FALSE,TRUE };

#define DEBUGLEVEL MEDIUM

#if DEBUGLEVEL < LOW

#define ASSERT(x)

#else

    #define ASSERT(x)\
    if(! (x))\
    {\
    std::cout <<"ERROR! Assert " << #x << " failed.\n";\
    std::cout <<" on line " << __LINE__ << "\n";\
    std::cout <<" in file " << __FILE__ << "\n";\
    }
    
    #endif

#if DEBUGLEVEL < MEDIUM
#define EVAL(x)
#else
#define EVAL(x)\
std::cout<<#x<<":\t"<<x << std::endl;
#endif


#if DEBUGLEVEL < HIGH
#define PRINT(x)
#else
#define PRINT(x)\
std::cout<<x<<std::endl;
#endif

class String
{
public:
    // constructors
    String();
    String(const char * const);
    String(const String &);
    ~String();
    
    char & operator[](int offset);
    char operator[](int offset) const;
    
    String & operator = (const String&);
    int GetLen()const {return itsLen;}
    const char * GetString()const {return itsString;}
    BOOL Invariants()const;
    
private:
    String(int);
    char * itsString;
    unsigned short itsLen;
};

BOOL String::Invariants()const
{
    PRINT("(String Invariants Checked)");
    return((BOOL) (itsLen && itsString) || (!itsLen && itsString) );
}

class Animal
{
public:
    Animal():itsAge(1),itsName("John Q. Animal"){ASSERT(Invariants());}
    Animal(int, const String&);
    ~Animal(){}
    int GetAge(){ASSERT(Invariants()); return itsAge;}
    void SetAge(int Age){ASSERT(Invariants()); itsAge = Age;
    ASSERT(Invariants());}
    String & GetName() { ASSERT(Invariants()); return itsName;}
    void SetName(const String & name)
    {ASSERT(Invariants()); itsName = name; ASSERT(Invariants());}
    BOOL Invariants();
private:
    int itsAge;
    String itsName;
};

BOOL Animal::Invariants()
{
    PRINT(("Animal Invariants Checked"));
    return (itsAge > 0 && itsName.GetLen());
}
int main()
{
    const int AGE = 5;
    EVAL(AGE);
    Animal sparky(AGE,"Sparky");
    std::cout<<"\n"<< sparky.GetName().GetString()<<" is ";
    std::cout << sparky.GetAge()<< " years old.";
    sparky.SetAge(8);
    std::cout<<"\n"<< sparky.GetName().GetString()<< " is";
    std::cout<< sparky.GetAge()<< " years old.";
}
Your enum BOOL is not the same thing as the built-in C++ type bool. As your compiler is telling you, you can't implicitly convert one to the other.

Why do you need that enum? Why can't you just use the built-in bool type?

its just an example in my book. I'm trying to learn about assert macro's. Can you show me how to make this compile with the built in bool? thanks.
Just... use the C++ bool type everywhere. If you don't know how to use it, I'm sure your textbook will show you. It's a very basic and fundamental part of C++, so you really should learn how to use it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
bool myFlag1 = true;
bool myFlag2 = false;

if (myFlag1)
{
  std::cout << "myFlag1 is true" << std::endl;
}
else
{
  std::cout << "myFlag1 is false" << std::endl;
}

if (myFlag2)
{
  std::cout << "myFlag2 is true" << std::endl;
}
else
{
  std::cout << "myFlag2 is false" << std::endl;
}
ok i tried my best with the inbuilt bool but its giving me 3 errors at the moment

line 74 to String::~String()

line 96 to Animal::Animal(int String const &)
to String::String char const*
to String::~String()

line 102 to String::~String()

thanks.

#include <iostream>

enum LEVEL { NONE,LOW,MEDIUM,HIGH };

//enum BOOL { FALSE,TRUE };

#define DEBUGLEVEL MEDIUM

#if DEBUGLEVEL < LOW

#define ASSERT(x)

#else

#define ASSERT(x)\
if(! (x))\
{\
std::cout <<"ERROR! Assert " << #x << " failed.\n";\
std::cout <<" on line " << __LINE__ << "\n";\
std::cout <<" in file " << __FILE__ << "\n";\
}

#endif

#if DEBUGLEVEL < MEDIUM
#define EVAL(x)
#else
#define EVAL(x)\
std::cout<<#x<<":\t"<<x << std::endl;
#endif


#if DEBUGLEVEL < HIGH
#define PRINT(x)
#else
#define PRINT(x)\
std::cout<<x<<std::endl;
#endif

class String
{
public:
// constructors
String();
String(const char * const);
String(const String &);
~String();

char & operator[](int offset);
char operator[](int offset) const;

String & operator = (const String&);
int GetLen()const {return itsLen;}
const char * GetString()const {return itsString;}
bool Invariants()const;

private:
String(int);
char * itsString;
unsigned short itsLen;
};

bool String::Invariants()const
{
PRINT("(String Invariants Checked)");
return((bool) (itsLen && itsString) || (!itsLen && itsString) );
}

class Animal
{
public:
Animal():itsAge(1),itsName("John Q. Animal"){ASSERT(Invariants());}
Animal(int, const String&);
~Animal(){}
int GetAge(){ASSERT(Invariants()); return itsAge;}
void SetAge(int Age){ASSERT(Invariants()); itsAge = Age;
ASSERT(Invariants());}
String & GetName() { ASSERT(Invariants()); return itsName;}
void SetName(const String & name)
{ASSERT(Invariants()); itsName = name; ASSERT(Invariants());}
bool Invariants();
private:
int itsAge;
String itsName;
};

bool Animal::Invariants()
{
PRINT(("Animal Invariants Checked"));
return (itsAge > 0 && itsName.GetLen());
}
int main()
{
const int AGE = 5;
EVAL(AGE);
Animal sparky(AGE,"Sparky");
std::cout<<"\n"<< sparky.GetName().GetString()<<" is ";
std::cout << sparky.GetAge()<< " years old.";
sparky.SetAge(8);
std::cout<<"\n"<< sparky.GetName().GetString()<< " is";
std::cout<< sparky.GetAge()<< " years old.";
}
Last edited on
ok i tried my best with the inbuilt bool but its giving me 3 errors at the moment

line 74 to String::~String()

line 96 to Animal::Animal(int String const &)
to String::String char const*
to String::~String()

line 102 to String::~String()

Those are not complete error messages. Why are you posting random substrings from the messages, rather than the whole messages?

Also, without code tags, those line numbers are meaningless.
c++ is case aware. If you accidentally put string instead of String, it will give a pile of errors, similar to earlier where you may have mixed BOOL and bool. Watch out for this (and consider calling your own stuff myString or something obvious, one letter different only in case is a recipe for typo problems that may be hard to spot).
Topic archived. No new replies allowed.