Saturday, June 7, 2008

Boost interview questions

- What is boost? And why is it useful?
- What is a shared pointer?
- What is the difference between shared pointer, auto pointer and intrusive pointer?
- How is shared pointer implemented internally?
- How would you convert from string to integer using boost?

#include
#include
#include

/*
Implement as simple a class as possible to pass the test case below.
If possible,
- use only a single container
- do not use a void pointer
- use any stl/boost/mpl algorithms that are of use
*/


class cNamedVariableContainer
{
public:
template
void manage(const std::string& name, T& varRef)
{
}

public:
void setValue(const std::string& namedVariable, const std::string& value)
{
}
};



int main()
{
cNamedVariableContainer nvc;

int myInt(0);
double myDouble(0.);
std::string myString("");

nvc.manage("int", myInt);
nvc.manage("dbl", myDouble);
nvc.manage("str", myString);

nvc.setValue("int", "43");
nvc.setValue("dbl", "123.8");
nvc.setValue("str", "hello");

std::cout << myInt << std::endl;
std::cout << myDouble << std::endl;
std::cout << myString << std::endl;

assert(myInt==43);
assert(myDouble==123.8);
assert(myString=="hello");

return 0;
}

0 comments: