I have a logicAND class, the constructor is supposed to evaluate the AND operation of two booleans, and it works this way:
class logicAND{
public:
logicAND(bool a,bool b):value(a&&b){}
bool output(){return value;}
private:
bool value;
};
int main(){
bool m=false;
bool n=true;
logicAND t1(m,n);
t1.output();
}
Then, I added some old style macros before the class:
typedef enum { False = 0, True = 1 } Bool;
#define bool Bool
#define true True
#define false False
class logicAND{
public:
logicAND(bool a,bool b):value(a&&b){}
bool output(){return value;}
private:
bool value;
};
int main(){
bool m=false;
bool n=true;
logicAND t1(m,n);
t1.output();
}
Now I can not make it work anymore. It seems the major problem lies in the constructor type mismatching.
It is appreciated for pointing out the pitfalls, reasons and solutions.
Thank you!
The main question is why you would want to do this. What do you want the macros to do, so to say, why do you want the bools to be enums?
However to see what is going wrong, you have to look at what your codes looks like after the preprossesor has replaced your macros:
So the reason why it breaks, is that you try to store a the bool returned from a&&b in a variable of type Bool. The obvious way to fix this would be to delte the macros. Or you need to explain why you need them.