hhey sir i need some information about his topic urgently

what do you want to know about it? c++ objects are normally passed by reference to avoid expensive duplication and to let other functions use the same object as the calling function.

class MyClass
{
  // blabla
};

void foo(MyClass& obj)
{
    // class passed by reference
}

int main()
{
    MyClass myclass; // create an instance of the class
    foo(myclass); // pass it to another function
}

They can also be passed as pointers, if you want to use them. Thought I believe it's considered better to use references over pointers when possible.

class MyClass
{
  // blabla
};

void foo(MyClass* obj)
{
    // class passed by reference
}

int main()
{
    MyClass myclass; // create an instance of the class
    foo(&myclass); // pass it to another function

    //or....
   MyClass* myclass = new MyClass;//create a pointer to the class and allocate an object at its location
   foo(myclass);//call the function
   delete myclass;//deallocate the object
}

Can u plz explain the internals of passing object reference to a function as parameter....that at the compiler level what will happen if i pass object as value and what will happen if i pass objet as reference to a function as parameter

what all will be invoked(like copy construtor) if i pass object as pass by value to fun and if i pass objecct as pass by referene

why shud i pass object as reference in copy construtor? what happens if i dont pass it as reference..can some give me a code to test it

You really need to start reading a book, because a book will explain all the questions your are asking. See amazon.com for a list of good c/c++ intro books.

Many of your questions can be answered, as Ancient Dragon suggests, by reading a book. Another appraoch that I find very useful (especially for C++ hidden behavior) is to write a small sample program to test things out. If you write a small class with a copy constructor, assignment operator, constructor, destructor and other methods you might want to evaluate each with a std::cerr print statement in them you will see where each is invoked.

This article has been dead for over six months. Start a new discussion instead.