0
1

আমি যদি C++ এ একটা Class মধ্যে একটা ফাংশন তৈরি করি এবং ফাংশনের প্যারামিটার হিসেবে কোন অবজেক্টকে পাঠানো হয় যেমন

class Test{

public:
       Test show(Test obj)
       {
          Test tt;  
          tt.x=20;   
          return tt;
       }
};

এখানে প্রথমে Test obj এবং retun tt এর জন্য ডেস্ট্রাক্টর কল হচ্ছে কিন্তু কোন কন্সট্রাক্টর তৈরি হচ্ছে না

asked 09 Feb '15, 12:29

razibchamp's gravatar image

razibchamp
935

edited 10 Feb '15, 08:01


When you are passing an object to a function, it is being passed by reference. So instead of copying the object, the function is just using the base object that was already created. As no object is being created here, the constructor is not being called and when the work is done, the destructor for the base object is called to free up the memory

permanent link

answered 12 Feb '15, 04:56

Shubho%20Brata%20Roy's gravatar image

Shubho Brata Roy
112

edited 12 Feb '15, 04:58

When you are passing an object to a function, it is being passed by reference. So instead of copying the object, the function is just using the base object that was already created. As no object is being created here, the constructor is not being called and when the work is done the destructor for the base object is called to free up the memory

permanent link

answered 12 Feb '15, 05:01

Shubho%20Brata%20Roy's gravatar image

Shubho Brata Roy
112

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×131
×6
×5
×1

question asked: 09 Feb '15, 12:29

question was seen: 1,100 times

last updated: 12 Feb '15, 05:01