Function Overload Question
-
Hello again, all. I need help with function overloads. I have overloaded a class constructor but its not working. I added the second constructor and thought I could call the original and save a lot of typing. ref MyClass{ int ProductValue; MyClass(array^ arrIn) { ///Do lots of stuff ProductValue = arrIn[0] * arrIn[1]; } MyClass(int i, int j) { array^ newArr = gcnew array(2); newArr[0] = i; newArr[1] = j; MyClass::MyClass(newArr); }}; myCobj = gcnew MyClass(4,6); ///myCobj->ProductValue = 0 and not 24 When I call the 1st constructor everything works fine. But calling the second constructor does not return an initialized object. i.e. ProductValue is 0 (zero) instead of 24 (for example).
-
Hello again, all. I need help with function overloads. I have overloaded a class constructor but its not working. I added the second constructor and thought I could call the original and save a lot of typing. ref MyClass{ int ProductValue; MyClass(array^ arrIn) { ///Do lots of stuff ProductValue = arrIn[0] * arrIn[1]; } MyClass(int i, int j) { array^ newArr = gcnew array(2); newArr[0] = i; newArr[1] = j; MyClass::MyClass(newArr); }}; myCobj = gcnew MyClass(4,6); ///myCobj->ProductValue = 0 and not 24 When I call the 1st constructor everything works fine. But calling the second constructor does not return an initialized object. i.e. ProductValue is 0 (zero) instead of 24 (for example).
The call
MyClass::MyClass(newArr);
will create a new temporary object. Change it tothis->MyClass::MyClass(newArr);
«_Superman_» I love work. It gives me something to do between weekends.
-
The call
MyClass::MyClass(newArr);
will create a new temporary object. Change it tothis->MyClass::MyClass(newArr);
«_Superman_» I love work. It gives me something to do between weekends.