assignment operator with multiple arguments?

Aug 20, 2010 at 1:08pm
I would like to assign an object of a class C, from multiple parameters in differnet variables.
I could make a structure containing all those parameters and an assignment operator for this type, but that would mean an additionnal copy of the value or address of each parameter.
Are we allowed to define an assignmeent operator
C& C::operator=(P1 param1, P2 param2);
that would be callled like
1
2
C c1;
c1 =(32,"apple");

Aug 20, 2010 at 2:01pm
No. Even if C++ allowed it, it would be a bad idea. The whole point of overloading operators is to make the code more intuitive and natural.

cl = (32,"apple"); is not intuitive or natural. It's weird and unwieldly.

No need for the assignment operator here. Just have a Set or Assign function:

 
cl.Set(32,"apple");
Aug 20, 2010 at 2:12pm
Or call a constructor explicitly:
 
c1 = C( 32, "apple" );
Last edited on Aug 20, 2010 at 2:13pm
Aug 20, 2010 at 2:13pm
Ok thanks,
I would have prefered an 'automatic' assignment from my set of parameter to my class C. I will maybe also create a new constructor.
Topic archived. No new replies allowed.