Skip to content
Related Articles

Related Articles

Improve Article

C++ | Operator Overloading | Question 10

  • Last Updated : 28 Jun, 2021

Which of the following operator functions cannot be global, i.e., must be a member function.
(A) new
(B) delete
(C) Converstion Operator
(D) All of the above

Answer: (C)

Explanation: new and delete can be global, see following example.


using namespace std;

class Myclass {
    int x;
    friend void* operator new(size_t size);
    friend void operator delete(void*);
    Myclass(int i) {
        x = i;
        cout << "Constructor called \n";
    ~Myclass() { cout << "Destructor called \n"; }

void* operator new(size_t size)
    void *storage = malloc(size);
    cout << "new called \n";
    return storage;

void operator delete(void *p )
    cout<<"delete called \n";

int main()
    Myclass *m = new Myclass(5);
    delete m;
    return 0;

Quiz of this Question

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :