mat.viguier mat.viguier -3 years ago 149
C++ Question

How to write correct a 2-input OOP'd NAND object in C++?

Say the following stuff pass

#include <iostream>

class Nand{
public :
bool A;
bool B;
bool s() const;
};

bool Nand::s() const {
return (!(A&&B));
};

int main()
{
std::cout << std::boolalpha;

Nand Nand_1;
Nand_1.A = true;
Nand_1.B=false;
bool Y = Nand_1.s();

std::cout << "Input A of Nand_1 is equivalent to : " << Nand_1.A << std::endl;
std::cout << "Input B of Nand_1 is equivalent to : " << Nand_1.B << std::endl;
std::cout << "Output Y of Nand_1 is equivalent to : " << Y << std::endl;

return 0;
}


and this one too

#include <iostream>

class Nand{
public :
bool s(bool iA, bool iB) const;
};

bool Nand::s(bool iA, bool iB) const {
return (!(iA&&iB));
};

int main()
{
std::cout << std::boolalpha;

Nand Nand_1;
bool Y = Nand_1.s(true, false);

//std::cout << "Input A of Nand_1 is equivalent to : " << Nand_1.A << std::endl;
//std::cout << "Input B of Nand_1 is equivalent to : " << Nand_1.B << std::endl;
std::cout << "Output Y of Nand_1 is equivalent to : " << Y << std::endl;

return 0;
}


Sboxes are made by simple 2-input Nand connected together.
I want to template the Nand class in order to generate complex Sboxes.
In fact the () function is showed with two inputs in this snippet.
I manage arrays input of at least 128 bits.

Fisrt stuff is not well written.
The second one permits linking in between, but doesn't permirt to show inputs of s !

How can I read s parameters in the second stuff ?
I can with the first snipppet, but I think it is not well written (in order to template later).

That rocks me :(

Answer Source

Moved to C without OOP since a while. Each NAND function call subfunction to export what I need. Closed unanswered.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download