Can Operator be Variable

Nilay Pachauri
Posts: 20
Joined: Sat Jun 13, 2015 4:11 pm

Can Operator be Variable

Postby Nilay Pachauri » Thu Sep 24, 2015 10:14 pm

Can I assign a variable an operator? i.e.

Code: Select all

x = *
so if i call

Code: Select all

3x4
it will return

Code: Select all

12
I like Goat Milk
--Nikhil Pathak (2015)

mrPogace
Site Admin
Posts: 46
Joined: Wed Apr 29, 2015 4:03 am

Re: Can Operator be Variable

Postby mrPogace » Fri Sep 25, 2015 7:12 pm

You can overload operators to do a lot of silly things but 'x' is not a operator. So you can not overload 'x' to do multiplication.

Nilay Pachauri
Posts: 20
Joined: Sat Jun 13, 2015 4:11 pm

Re: Can Operator be Variable

Postby Nilay Pachauri » Fri Sep 25, 2015 10:34 pm

So can i like overload * to add instead of multiply and + to multiply instead of add?
I like Goat Milk
--Nikhil Pathak (2015)

mrPogace
Site Admin
Posts: 46
Joined: Wed Apr 29, 2015 4:03 am

Re: Can Operator be Variable

Postby mrPogace » Mon Sep 28, 2015 2:56 am

In some cases yes. Please never do this... ever.

Nilay Pachauri
Posts: 20
Joined: Sat Jun 13, 2015 4:11 pm

Re: Can Operator be Variable

Postby Nilay Pachauri » Mon Sep 28, 2015 3:18 am

We'll see. It might come in handy one day. :mrgreen:
I like Goat Milk
--Nikhil Pathak (2015)


Return to “Miscellaneous”

Who is online

Users browsing this forum: No registered users and 1 guest