Overload of operator!

I'm trying to overload operator! for my class, but I receive error: 'void myClass<T>::operator!(const char&)' must take 'void'.
Is it possible to overload operator! ?
Is it possible to overload operator! ?
Yes.

void myClass<T>::operator!(const char&) exhibits a conceptual error. What is this member function supposed to do?
Last edited on
The ! operator should not have any parameters. The only (implicit) parameter is the instance of the class itself.

See: http://www.cplusplus.com/forum/general/74202/ (vlad's post)
Last edited on
So I have a problem. I have to make class Not to simulate not gate.
No problem with operator! when the input is a bool, but there could be also the input 'x' (undefined). When I receive in input a character, my idea was to overload operator! to give in output the same character 'x'.
> I have to make class 'Not' to simulate 'not' gate.
I suppose that you'll also have classes for others operations, like 'And', 'Or', 'Xor'
think how they will be used
1
2
3
4
5
6
7
Input A, B;
Or g1(A, B);
A.set();
B.reset();
cout << g1.output() << '\n'; //prints 1 (True)
A.toggle();
cout << g1.output() << '\n'; //prints 0 (False) 
note that there is no operator overload
each kind of gate has some Inputs, and perform an operation based on their state

An alternative is to have member functions to the operations, then you may write
1
2
3
Input A, B;
(A.Or(B)).And( (B.And(True)).Not() );
(A + B) * !(B*True); //with operator overloading 
that may be done like
1
2
3
4
5
6
7
class Input{
   char state; //0, 1, 'x'
public:
   Input Or(Input b) const; //as a member function
   Input Not() const;
};
Input And(Input a, Input b); //as a non-member function (¿friend?) 
note the signatures, they take Input objects and return an Input object
if you want to overload the operators they will follow the same signature
1
2
3
4
5
6
Input Input::operator!() const{
   //return this->Not(); //equivalent
   if(state == 0) return Input(1);
   if(state == 1) return Input(0);
   return Input('x');
}
Last edited on
Topic archived. No new replies allowed.