C++ class to create a new type Boolean with the two values F and T defined.

Sep 4, 2020 at 7:55am
Use a C++ class to create a new type Boolean with the two values F and T defined. Use the C++ class/struct keyword and an array to create a list of pairs that cover all possible combinations of the 2 Boolean constants you defined.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>


class Boolean {
public:
bool F = false;
bool T = true;

Boolean array[4] = {Boolean(T,T)), Boolean(T,F), Boolean(F,T), Boolean(F,F};


};


I am not sure is this correct because I got this information 'warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]'. Could somebody help me Pleaseeee!
Sep 4, 2020 at 10:08am
I not sure I really understand the question, but consider:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <utility>
using namespace std;

struct Boolean {
	enum class val {F, T};

	Boolean(val _v) : v(_v) {}

	val v;
};

int main()
{
	const pair<Boolean, Boolean> array[] = {{Boolean::val::T, Boolean::val::T},
						{Boolean::val::T, Boolean::val::F},
						{Boolean::val::F, Boolean::val::T},
						{Boolean::val::F, Boolean::val::F}};
}

Last edited on Sep 4, 2020 at 4:33pm
Sep 4, 2020 at 10:26am
Look at this.

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

// C++17

using namespace std;

enum class bvalue {F,T};

struct Boolean
{
    bvalue value {bvalue::F};
};

template< class T , class... U >
array( T , U... ) -> array< T , 1 + sizeof...(U) >;

int main()
{
    const array booleanlist { make_pair(bvalue::T,bvalue::T),
                              make_pair(bvalue::T,bvalue::F),
                              make_pair(bvalue::F,bvalue::T),
                              make_pair(bvalue::F,bvalue::F)  };
    return 0;
}

Topic archived. No new replies allowed.