Problem with passing pointer to a function

Discussion in 'C++' started by Than, Aug 1, 2003.

  1. Than

    Than Guest

    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
     
    Than, Aug 1, 2003
    #1
    1. Advertising

  2. "Than" <> 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
     
    Victor Bazarov, Aug 1, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Newsgroup - Ann
    Replies:
    5
    Views:
    609
    John Carson
    Jul 30, 2003
  2. James Vanns
    Replies:
    7
    Views:
    7,041
    Evan Carew
    Jan 21, 2004
  3. beetle
    Replies:
    2
    Views:
    911
    beetle
    Jan 25, 2005
  4. jimjim
    Replies:
    16
    Views:
    842
    Jordan Abel
    Mar 28, 2006
  5. Vijai Kalyan
    Replies:
    4
    Views:
    708
    Vijai Kalyan
    Nov 8, 2005
Loading...

Share This Page