Thread: overload new and delete

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    175

    overload new and delete

    Why do one need to overload operators like new and delete. And also curious to know, why do people overload ‘[]’ operator?

    Please let me know..

    Thanks

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    new and delete are overloaded in case someone wanted to redefine the way memory was allocated. operator[] is overloaded for bounded arrays like a std::vector:

    std::vector<int> a;
    a.push_back(3);
    std::cout << a[0] << std::endl; //prints out 3

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    You should be able to overload as many operators as possible so you have the flexibility to define them the way you want them to operate on your class.

Popular pages Recent additions subscribe to a feed