Manhattan associates Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




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

Only on Stack. Make new operator private.
Only on Heap. Make Destructor private.

- Dr.Sai December 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what's the matter of making destructor private ?

I think the easiest way is to provide a static func
to construct the objects of your class (whenever you like)
and declare the constructor private

- Anonymous December 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

if destructor is private.. GC cant collect it.

- Kshitij December 06, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

but what if there is no automatic GC like in conventional C++ ?
then I suppose making destructor private does not make much sense

- Anonymous December 06, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

For stack: make the constructor and destructor private, and provide friend or static functions that perform the same functionality.
For Heap: overload the new function and make it private.

- Ella June 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What is the language/environment C, C++, C++ with GC, .NET, Java?

Thanks,
Laxmi

- Laxmi Narsimha Rao Oruganti December 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

only on heap -> Destructor should be private. Reason, compiler can't call destructor. So, compiler stops creation of object on stack. This is applicable to all compilers.

- srik545 January 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Then how do you delete the object if destructor is private?

- sefuns January 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

create a public function and call the destructor inside

or this can work ....

clear( )
{
delete this;
}

- swarnx February 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In order to prevent clients to create object on heap, you would need to make new/delete, placement new/delete operators private. And make all constructor and destructors private to avoid object creation on stack by client. Now one can't create any instance of your object. So you would need to provide a static method for object creation/deletion.

Here is an example:

class myclass
{
private:
    void* operator new(size_t);          // standard new
    void* operator new(size_t, void*);   // placement new
    void* operator new[](size_t);        // array new
    void* operator new[](size_t, void*); // placement array new
 
  myclass() {}
  ~myclass(){}

public:

myclass & createObject()
{
return new myclass();
}

void destroyObject() const
{
   delete this;
}
}

- Dew Kumar March 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In order to prevent clients to create object on heap, you would need to make new/delete, placement new/delete operators private. And make all constructor and destructors private to avoid object creation on stack by client. Now one can't create any instance of your object. So you would need to provide a static method for object creation/deletion.

Here is an example:

class myclass
{
private:
    void* operator new(size_t);          // standard new
    void* operator new(size_t, void*);   // placement new
    void* operator new[](size_t);        // array new
    void* operator new[](size_t, void*); // placement array new
 
  myclass() {}
  ~myclass(){}

public:

myclass & createObject()
{
return new myclass();
}

void destroyObject() const
{
   delete this;
}
}

- Dew Kumar March 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In order to prevent clients to create object on heap, you would need to make new/delete, placement new/delete operators private. And make all constructor and destructors private to avoid object creation on stack by client. Now one can't create any instance of your object. So you would need to provide a static method for object creation/deletion.

Here is an example:

class myclass
{
private:
    void* operator new(size_t);          // standard new
    void* operator new(size_t, void*);   // placement new
    void* operator new[](size_t);        // array new
    void* operator new[](size_t, void*); // placement array new
 
  myclass() {}
  ~myclass(){}

public:

myclass & createObject()
{
return new myclass();
}

void destroyObject() const
{
   delete this;
}
}

- Dew Kumar March 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In order to prevent clients to create object on heap, you would need to make new/delete, placement new/delete operators private. And make all constructor and destructors private to avoid object creation on stack by client. Now one can't create any instance of your object. So you would need to provide a static method for object creation/deletion.

Here is an example:

class myclass
{
private:
    void* operator new(size_t);          // standard new
    void* operator new(size_t, void*);   // placement new
    void* operator new[](size_t);        // array new
    void* operator new[](size_t, void*); // placement array new
 
  myclass() {}
  ~myclass(){}

public:

myclass & createObject()
{
return new myclass();
}

void destroyObject() const
{
   delete this;
}
}

- Dew Kumar March 29, 2012 | Flag Reply


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