Jim Langston Guest
|
Posted: Wed Jul 12, 2006 9:10 am Post subject: How to make code accepting differet types work? |
|
|
This is something I've been thinking about creating, and am trying to get
the pieces together.
I want to be able to assign values in a method accepting different types.
I.E.
MyInstance.MyMethod("IntField") = 1;
MyInstance.MyMethod("FloatField") = 2.34f;
MyInstance.MyMethod("StringField") = std::string("Hello");
Is this possible?
I know I could do it using function overloading by passing the parms, I.E.
MyInstance.MyMethod("IntField", 1);
MyInstance.MyMethod("FloatField", 2.34f);
MyInstance.MyMethod("StringField", std::string("Hello");
I'm thinking to use the assignment I would need to return a LHV, a reference
to what was being assigned. I think I just answered my own question.
Whatever I am returning would need to have operator=() overloaded for each
type.
Is this the way to go? |
|