Problem with passing pointer to a function

T

Than

I'm having this kind of problem.

I've got a function which get's as the argument a pointer to an object. It
looks like this:

void DoCalculations(CMyClass* Class);
{
CMyClass temporaryClass = *Class;
return;
}

And when the function ends with return; in place from where it was called:

DoCalculations (&ExampleClass);

object ExampleClass has totally different fields' values, random i suppose.
What do i do wrong?

Operator
CMyClass& operator=(CMyClass& class);
is defined for the class.

Thanks for any help
Than
 
V

Victor Bazarov

Than said:
I'm having this kind of problem.

I've got a function which get's as the argument a pointer to an object. It
looks like this:

void DoCalculations(CMyClass* Class);
{
CMyClass temporaryClass = *Class;
return;
}

And when the function ends with return; in place from where it was called:

DoCalculations (&ExampleClass);

object ExampleClass has totally different fields' values, random i suppose.
What do i do wrong?

Operator
CMyClass& operator=(CMyClass& class);
is defined for the class.

That shouldn't matter. Do you have a copy-constructor defined?
It is most likely that you have some kind of dynamic memory used
in 'CMyClass' and you have forgotten to define a copy-constructor
or it is defined incorrectly. Read about "the Rule of Three".

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top