Stack Overflow Asked by Kai on December 19, 2020
I’m currently learning C and am now at the part of structs and lists.
I just wondered, if there ist something like "a = a+b" = "a += b" for this case.
No. You could use a macro, but i wouldn't.
Answered by 12431234123412341234123 on December 19, 2020
If you are using C++ then instead of the raw pointers you could define your own class of iterator for a list that internally contained the pointer p
.
In this case you could substitute the expression
p = p->next;
for the expression
++it;
that under the hood will do p = p->next
.
Something like
iterator & operator ++()
{
iterator::p = iterator::p->next;
return *this;
}
where the pointer p
is a data member of the class iterator
.
As for the compound assignment operator then there are no such operators like ->=
or .=
. So you can not overload them.
According to C and C++ Standards the assignment operator is one of
= *= /= %= += -= <<= >>= &= ^= |=
Answered by Vlad from Moscow on December 19, 2020
1 Asked on January 12, 2021 by karthik
2 Asked on January 12, 2021
3 Asked on January 12, 2021 by redouane-nouh
0 Asked on January 12, 2021 by mario-tunon
1 Asked on January 12, 2021 by nachengue
1 Asked on January 12, 2021 by vivz
1 Asked on January 12, 2021 by user13380366
1 Asked on January 11, 2021 by mr-spock
2 Asked on January 11, 2021 by edi_hadzic
2 Asked on January 11, 2021 by steven85791
1 Asked on January 11, 2021 by eka-buyung-lienadi
1 Asked on January 11, 2021 by york910
3 Asked on January 11, 2021 by alejandro-navas
1 Asked on January 11, 2021 by brian-yeh
Get help from others!
Recent Questions
Recent Answers
© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP