Nisum Technologies Interview Question






Comment hidden because of low score. Click to expand.
0
of 0 vote

destructor will go into infinate loop....

- sekhar740 November 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

delete statment has 2 tasks to do:
1. call jobject`s destructor
2. free object`s memory by calling operator delete()

So, when delete this is being called in dcor, we have a infinite loop: dtor(delete this) -> dcor(delete this) -> ...

- Anonymous November 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1)The this object must have been allocated via new not by new[] nor by placement new nor by a local object on the stack nor by a global nor by a member of another object. It has to have been allocated by plain, ordinary new.

2) The member function that contains delete this; must be the last member function that is invoked on the this object.

3) The remainder of the member function after the delete this; line must not touch any piece of the this object, including calling any other member functions or touching any data members.

4) No other piece of code should even examine the this pointer itself after the delete this; line. No one may examine it, compare it with another pointer, compare it with NULL, print it, cast it, do anything with it.

5) Make sure no one else does a delete on the object. For example, if the object is still being held by an auto_ptr (which would be a good thing!), the release() member function must be called on the auto_ptr; otherwise the auto_ptr will delete the object again, which would be a disaster. For example:
#include <iostream>
using namespace std;

class Fred {
public:
Fred();
virtual ~Fred();
virtual void discard() throw();
};

void Fred::discard() throw()
{ delete this; }

- Anonymous November 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

1. Any object which has delete this; in dtor (i.e. objects created by new, by new[], on stack, global objects, static objects) will overfill stack by calling dtor()->dcot()->... and as result it will crash programm. Look inside delete statement or just try to create object on stack with @delete this@ in dtor.

- Anonymous November 29, 2010 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More