Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7766289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:22:38+00:00 2026-06-01T15:22:38+00:00

I have a logicAND class, the constructor is supposed to evaluate the AND operation

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:22:39+00:00Added an answer on June 1, 2026 at 3:22 pm

    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:

    class logicAND
    {
    public:
        logicAND(Bool a,Bool b):value(a&&b){} //Expects two Bools which works. Now it trys to do a&&b, this actually is well defined for enums. However it returns a bool (!) which cannot be stored in "value" since that is a Bool.
        Bool output(){return value;}
    private:
        Bool value; //This now is a Bool! Not a real bool
    };
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long story short Say I have the following code: // a class like this
I have a Junit test class with two tests in it. test 1 will
Suppose I have a following constructor in C++ class: MyClass::MyClass() { char* buffer =
I have a Paper class that has 4 attributes. public class Paper(int id, String
I have program with two files; main.py that has my main logic and class.py
I have the following pojo: public class Foo { @Size(min=0,max=10) private String bar =
I have two projects, the DLL project which has all my logic and data
I have two projects in my Solution. One implements my business logic and has
Have a singleton class for BNRItemStore, but when I tried to call it, I
The preamble: I have designed a strongly interfaced and fully mockable data layer class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.