Original Post
alright, so I am working on a calculator. I was originally had a system that would pass values (complex numbers, lists, matrices) using the stack like this. This is the function I was using This would work but I polymorphism wasn't working with my lists and matrices so I put ALL the code for complex numbers, lists, and matrices into one source file. This would work but my code was a pain to manage and it was difficult to add now types (strings) to my calculator. So I decided to have get value work like this This is how I have it set up right now. This works great. Except it is way slower now. I suspect it has something to do with having to create now objects and them deleting them. Can anybody suggest any way to improve upon this system?
void GetValue(CNumber* result)
{
// logic code here
// result is usually a class allocated on the stack by the caller
// would look something like this
// CNumber number = CComplexNumber(0.0, 1.0);
// GetValue(&number);
*result = (return value);
}
CNumber* GetValue()
{
// logic code here
// involves creating an object with the 'new' operator
// caller function will take returned value, use it, then delete it.
return (return value);
}