QuantLib or more general C++

L

louis.ocarroll

Hi there,

If anyone has experience with quantlib, how do I initialize a Bond
Class??
If not, here is a more generalized C++ question :)
I have a initialized an object with the constructor, which is protected
on the Bond class, and when I try to compile a line initializing a
object of the Bond Class, it complains that it is protected.
Can anyone help me out??

Thanks,
Louis
 
G

Gavin Deane

Hi there,

If anyone has experience with quantlib, how do I initialize a Bond
Class??
If not, here is a more generalized C++ question :)
I have a initialized an object with the constructor, which is protected
on the Bond class, and when I try to compile a line initializing a
object of the Bond Class, it complains that it is protected.
Can anyone help me out??

Only classes derived from Bond can instantiate Bond objects using a
protected constructor. If the Bond class has another constructor that
is public, you can instantiate a Bond object using that constructor.
Otherwise the only thing you can do is instantiate an object of a type
derived from Bond.

Gavin Deane
 
L

louis.ocarroll

Thanks for the swift answer :)

If it woudn't be to much of a burden, could you provide a small
example?? :)

Thanks
 
B

Ben Pope

Thanks for the swift answer :)

If it woudn't be to much of a burden, could you provide a small
example?? :)

class Bond {
protected:
Bond() : i_(0) {}
Bond(int i) : i_(i) {}
private:
int i_;
};

class Derived : public Bond {
public:
Derived() : Bond() {}
Derived(int i) : Bond(i) {}
};


int main() {
//Bond b1; // protected constructor
//Bond b2(5); // protected constructor
Derived d1;
Derived d2(5);
}


Ben Pope
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top