Bloomberg LP Interview Question
Financial Software DevelopersI had same experience with Bloomberg.
Very tuff people and very arrogant attitude.
Ready to turn you down at any cost.
I wonder why they waste everyone's time if they are ready to ask questions which they never used or never make sense to use in programming.
Salary what they offer is also very low compare to other financial institutes
Q5.
auto_pointer<Object> a(new Object());
auto_pointer<Object> b(new Object());
a = b;
It's invalid. The reason is as follows:
Notice however that the left-hand side object is not automatically deallocated when it already points to some object. You can explicitly do this by calling member function reset before assigning it a new value.
(from cplusplus_com)
In order to make it valid, we could change the code to
auto_ptr<Object> a(new Object());
auto_ptr<Object> b(new Object());
a.reset();
a = b;
Q5.
auto_pointer<Object> a(new Object());
auto_pointer<Object> b(new Object());
a = b;
It's invalid. The reason is as follows:
Notice however that the left-hand side object is not automatically deallocated when it already points to some object. You can explicitly do this by calling member function reset before assigning it a new value.
(from cplusplus_com)
In order to make it valid, we could change the code to
auto_ptr<Object> a(new Object());
auto_ptr<Object> b(new Object());
a.reset();
a = b;
Q5.
auto_pointer<Object> a(new Object());
auto_pointer<Object> b(new Object());
a = b;
It's invalid. The reason is as follows:
Notice however that the left-hand side object is not automatically deallocated when it already points to some object. You can explicitly do this by calling member function reset before assigning it a new value.
(from cplusplus_com)
In order to make it valid, we could change the code to
auto_ptr<Object> a(new Object());
auto_ptr<Object> b(new Object());
a.reset();
a = b;
Q5.
auto_pointer<Object> a(new Object());
auto_pointer<Object> b(new Object());
a = b;
It's invalid. The reason is as follows:
Notice however that the left-hand side object is not automatically deallocated when it already points to some object. You can explicitly do this by calling member function reset before assigning it a new value.
(from cplusplus_com)
In order to make it valid, we could change the code to
auto_ptr<Object> a(new Object());
auto_ptr<Object> b(new Object());
a.reset();
a = b;
reset is not needed. Here it clearly states "If the (left-hand side) object was being used to point to an object before the operation, the pointed object is destroyed (by calling operator delete)."
This can be verified easiler, just create a simply class and check if left side object is destroyed or not. See attached code
#include <string>
#include <iostream>
#include <memory>
using namespace std;
class A{
string mName;
public:
A(string name) { mName = name; }
~A(){ cout << "~A" << mName << endl;
}
};
main()
{
auto_ptr<A> ap1(new A("p1") );
auto_ptr<A> ap2(new A("p2") );
ap1.reset();
cout << "Here after reset" << endl;
ap1 = ap2;
cout << "Here after assignment" << endl;
}
1. Can you have private destructor and private constructor ? explain your answer.
- asuran October 13, 2008yes, like the realization of singlton
2. Can you have virtual constructor ? explain your answer.
No, at that time , the vtbl is not be constructed the function call will can't be the dynamic bound
3. What design pattern is similar to virtual constructor ?
abstract factory
4. Can you have vector of auto_pointer ? explain your answer.
no, it can 't be auto counted in STL container
5. is this code valid:
auto_pointer<Object> a(new Object());
auto_pointer<Object> b(new Object());
most likely valid