Category : operator-overloading

I overloaded new operator. But I wonder how compiler identified the type when I called the global new operator inside overloaded new operator. #include<iostream> class Samp{ public: Samp(){ std::cout<<"constructorn"; } void* operator new(size_t sz){ std::cout<<"operator overloading newn"; return ::operator new(sz); } }; int main(){ Samp* a=new Samp; return 0; } Here, the output is – ..

Read more

I am trying to make an operator >> for a string class I had to create for school, but I constantly get this error: ‘Segmentation fault (core dumped)’. Here is my class: class String { private: char *data; size_t size; public: String(); String(const String &); String &operator=(const String &); String(const char *data); ~String(); friend std::istream& ..

Read more