overload new and delete

This is a discussion on overload new and delete within the C++ Programming forums, part of the General Programming Boards category; Why do one need to overload operators like new and delete. And also curious to know, why do people overload ...

  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,493
    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,662
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21