By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Problem with passing pointer to a function

P: n/a
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


Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Than" <th**@gazeta.pl> wrote...
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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.