Goldman Sachs Interview Question for Software Engineer / Developers






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

Compiler synthesizes non trivial default constructors in following 4 cases only .
1. If a Class has a member of another class and that class has a default constructor.
e.g. Since class FOO has a default constructor therefore compiler will synthesize the same for Bar class as well.
class FOO
{
int a;
public:
FOO() {};
}
class Bar
{
FOO f;
};

2. Compiler synthesizes constructor for Derived class if base class also has a derived class constructor.

3. Either of Base class or Derived class has virtual method in it.
4. class is inherited as virtual base class.

- RS February 14, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

in other cases compiler may create a trivial default constructor but that does not guarantee initialization of Data members.

- RS February 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think whenever there is no user defined constructor(s), it is mandatory for the compiler to generate a default constructor. No?

- JJ February 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

No, thats not true.
refer C++ Primer from Lippman.

- RS February 19, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I still dont get it. For example, in your first case, you mentioned "Since class FOO has a default constructor therefore compiler will synthesize the same for Bar class as well.
class FOO
{
int a;
public:
FOO() {};
}
class Bar
{
FOO f;
};
"

So you mean even if I add a non-default constructor for Bar, the compiler will still synthesize a default constructor? I dont think so.

Could you kindly point me to the related section in C++ Primer? Thanks.

- JJ February 22, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

nice

- siva.sai.2020 May 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

JJ was right

- bbc July 04, 2012 | 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