Akamai Interview Question for Applications Developers


Country: India




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

There are three ways to address this that I know of:

1. boost::any (and the subsequent API that goes with it)
2. void* (that can point to any type of object)
3. Create a generic base class that all of your different types inherit from, then you can create lists and arrays of the parent type for any of the children.

Be mindful with void* as it is not as type-safe as using boost::any.

The drawback to the parent class is that it can overlap and violate the paradigm of modular programming if the items are from items of vastly different types and hierarchies.

You will need to search for the boost api to get all of the details.

- masterjaso July 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I prefer use boost::variant in most cases. You can read about boost any vs variant differences in boost online doc (unfortunately this site does not allow links)

- michael@videlgauz.com July 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

Union type.

- alpha July 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Approach 2 is not safe to use. Even how do you define the pop()? You can't simply return void*.

Approach 3 will not work for primitive type.

Can you please how you define pop() in approach 1?

- Hello world July 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Approach 3 will not work for primitive types, thus you can use method 1 or 2. #1 is the preferred method in my opinion.

To pull a value out of a void*, you are required to know what is going to come out as it is being used, thus the danger or utilizing it.

To pop from method 1, you would use value = boost::any_cast<T>(list) to return a value from the desired container.

- masterjaso July 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Create wrapper classes for primitives and thus you can get approach 3 work for primitives as well :)
e.g. A wrapper for integer:

class Integer{
public:
	int value;
	Integer(){
		value = 0;
	}
	Integer(int x){
		value = x;
	}
};

- EOF July 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

struct listval
{
int type; // 1 for char,2 for int,3 for double,4 for string
void *p;
}

std::list<struct listval> cont;





map<int,void *>

- Raj July 05, 2013 | 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