Nisum Technologies Interview Question






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

D *d = static_cast<D*>(b);
d->show(*d);

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

use dynamic_cast instead

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

why? classes are not polymorphic

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

Interview person intentionally asked this question...
if class has polymorphic calls then only dynamic_cast is used..

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

(D *)b->show(static_cast<D *)(b));

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

ะก-style cast and C++ style cast = dirty code, by the way show() expects D&, not D*. And there`s no ">".

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

dec

- Anonymous January 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

(D*)(static_cast<D*>(b)).show(D())

- Anonymous January 30, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Below code and it's output should answer all these questions. instead of static_cast, you can use reinterpret cast as well.

#include <iostream>
using namespace std;

class D;

class B
{
public:
void disp(){cout<<"Bas disp"<<endl;}
void show(int i){cout<<"Bas show with int"<<endl;}
void show(D& d1){cout<<"Bas show with D"<<endl;}
void gets(){cout<<"Bas gets"<<endl;}
};

class D : public B
{
public:
void disp(){cout<<"Dir disp"<<endl;}
void show(){cout<<"Dir show"<<endl;}
void puts(){cout<<"Dir puts"<<endl;}
};
int main()
{
D dd;
B *b = new D();
D *d = static_cast<D*>(b);
d->B::disp();
d->show();
d->B::show(10);
d->B::show(dd);
d->puts();
d->gets();
b->disp();
b->show(20);
b->gets();
}

Dir show
Bas show with int
Bas show with D
Dir puts
Bas gets
Bas disp
Bas show with int
Bas gets

- WinWin January 30, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use can achieve this by making use of "using Base::show" . This called name hiding in C++.

- Maulish May 11, 2011 | 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