Bool array constructor

I want ot overload operator & and | to do operations with bytes( probrably there will be away using a specific function from any library, but I want to do like this to learn..)but I'm having trouble making the construtor of two bool arrays...what I have done is this...

1
2
3
4
5
6
7
8
 lass arithmetic{
public:
	
	bool word1[8];
	bool word2[8];

arithmetic(bool x[8],bool y[8]): word1(x),word2(y);


and later I would overload operator to do logic operation with and and or...any help?

Thanks!!
Unfortunately, you cannot initialize an array with another array.

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
#include <algorithm>

struct Word {
    static const std::size_t byte_size = 8;
    static const std::size_t bytes = 2;


    Word() { std::fill_n(*byte, bytes * byte_size, false); }

    Word(const bool* a, const bool* b)
    {
        std::copy(a, a + byte_size, byte[0]);
        std::copy(b, b + byte_size, byte[1]);
    }

private:
    bool byte[bytes][byte_size];
};

int main()
{
    bool a [] = { false, true, false, true, false, true, false, true };
    bool b [] = { true, true, true, true, false, false, false, false };

    Word word1(a, b);
    Word word2;

}
I have tryed to use fill_n from aalgorithm and it says that mu class doesnt have any filed named 'filled_n'.....It belongs to algorithm so It should be read at any point of the program,shouldnt it?
1
2
3
4
5
6
7
8
9
10
11
12
13
14

class arithmetic{
public:
	int a;
	int b;
	bool Z;
	bool Y;
	bool word1[];
	bool word2[];
	arithmetic () {};
	arithmetic(int x,int y) : a(x),b(y),Z(false),Y(false),fill_n(*word1,8,false),fill_n(*word2,8,false){};


I' m using that function in my constructor, maybe It can be done I dont know, maybe I cant initialize an array in the constructor and It must be set later on..
Calling a function is not initializing an array. You must call the function in the body of the constructor, as I did. That is, the function must be called between the braces which enclose the body of the constructor.

By the way, lines 8 and 9 of your last code snippet are illegal in C++. You must provide the size of the arrays.
Topic archived. No new replies allowed.