Help reviewing C++ Test

Hi There. This is my fist post. I'm an aspiring programmer looking for a position as a C++ programmer. I am currently an iOS developer as well as having experience with C# in Unity, but my C++ is not as strong as my skill with these other languages. I recently applied to a company for a mid level C++ programmer. I don't want to disclose the name because they asked my not to share the test publicly. The test they sent me was pretty complex and definitely more advanced than I expected so I did not get the position. I would really like to know what I did wrong, what I did right, and what I could of done better so I can learn from the experience and hopefully improve myself. The test was to complete a container class they has which was like a memory pool. I was passed in a char * and that was the only memory I could use. I thought I had it going in the right direction, but I definitely did not get it right because it would crash when I ran it and like I said, it was more advanced than I was used to.

Iwas wondering if there were any C++ experts that wouldn't mind taking 5 or 10 minutes looking at my class and letting me know where I went wrong. I would really appreciate it and I really think if I could have my errors explained it would help to visualize why I did it wrong. The class is not too big, only about 200 lines.

If any body is willing to help a fellow programmer out I would be very greatfull. I don't want to post any code here because I agreed that I wouldn't publicly share it, but if you are willing to help I will PM you the file.

Thanks so much for anybody willing to take a look. You're really helping me out and helping me learn.


We can't review it if you don't post it.

Be sure and use code tags (the <> formatting button).
The company didn't give you any feedback regarding the test? I don't consider myself an expert but I can take a look at it, and try to give you some feedback tonight. But, honestly you will get better responses if you post it here. I do understand your reluctance to post it.
Last edited on
Thanks, I appreciate that. No I didn't get any feedback, just a generic email saying they had a better candidate.
Notice the Remove method didn't have a parameter name before, I added one. I was confused about that.

Function declarations don't have to name the parameters.
Two things I noticed glancing through it, in the ctor you only shallow copy the buffer pointer, and you dont delete anything in the dtor. I'll try to look at it more in depth when I have some time.

Edit: operator[] in a linked list?

Did you test the class? With template classes, you have to test each function as templates functions only compile as needed. NULL and assert are undefined, you need to include the correct headers. Also Add() crashes since you dont allocate any memory for the data you return.
Last edited on
It is a bad style to name variables starting with undescore. Such names are reserved by the implementation.

You defined an element as

template<typename T>
struct CItem
	T *data;
	CItem *next;
	CItem *prev;

For example if T is char then one element occupies 12 bytes on 32-bit system. I do not think that elements should be placed in a list. Only empty slots of the buffer could be placed in a single-linked list. If the addres of element is fixed it is easy to remove it.i You need not search it in the list of elements.

Also it seems that you do not know about mem-initializers for constructors.

I thinlk that it is the container that shall bother about freeing the buffer.
Last edited on
The assert in both operator[] is backward, should be assert(nIndex < _count);
@Vlad from moscow
I think he was given the header and had to implement it.
Notice the Remove method didn't have a parameter name before, I added one. I was confused about that.

You need not to include an identifier of a parameter if it is not used. It is common practice to omit names of parameters in function declarations that are not definitions.
Last edited on
Also the container shall not have copy semantic.
///====== Adds an element to the container, constructs it and returns it to the caller.
Here you would need to know what the in-place new is.
Last edited on
Topic archived. No new replies allowed.