এই টিউটোরিয়ালে আমরা C++-এ অবজেক্টের ডাইনামিক এলোকেশন কীভাবে বাধা দেওয়া যায় তা আলোচনা করব।
এ জন্য আমরা new অপারেটর ফাংশনকে প্রাইভেট রাখব যাতে অবজেক্টগুলো ডাইনামিক্যালি তৈরি করা না যায়।
উদাহরণ
#include <iostream> using namespace std; class Test{ //making new operator private void* operator new(size_t size); int x; public: Test() { x = 9; cout << "Constructor is called\n"; } void display() { cout << "x = " << x << "\n"; } ~Test() { cout << "Destructor is executed\n"; } }; int main(){ Test t; t.display(); return 0; }
আউটপুট
Constructor is called x = 9 Destructor is executed