Home

Friday, March 7, 2008

Variance, CoVariance, Expected value

Here are some wiki links! will add details later

Expected Value

Variance

Co Variance

Labels: ,

Thursday, February 28, 2008

RTTI

RTTI in Wiki

Difference between Dynamic Cast and static cast ?

C++ Some general Questions

Q) we can overload assignment operator as a normal function.But we can not overload assignment operator as friend function why?

Ans:) If the operation modifies the state of the class object, it operates on, it must be a member function, not a friend fucntionThus all operator such as =, *=, +=, etc are naturally defined asmember functions not friend functionsConversely, if the operator does not modify any of its operands,but needs only a representation of the object, it does not have tobe a member function and often less confusing.This is the reason why binary operators are often implemented asfriend functions sunch as + , *, -, etc..

Q Can you explain the term "resource acquisition is initialization?"

Ans ) Resource Acquisition is Initialisation or shortly RAII is a term closely connected with exception handling and automatic garbage collection(speaking loosely). RAII is defined as the technique of performing all necessary resource initialisation work right within the body of the constructor itself, and correspondingly doing all the deallocation within the destructor. Since during exception handling destructors of all the classes whose constructors have been successfully invoked, are called therefore all the local objects previously allocated are automatically deallocated without explicitly calling their destructors.the following example explains the RAII technique:class X{ int *r; public: X(){cout<<"X is created"; r=new int[10]; } ~X(){cout<<"X is destroyed"; delete [] r; }};class Y{ public: Y(){ X x; throw 44; } ~Y(){cout<<"Y is destroyed";}};Now since Y throws an exception right in its constructor therefore its destructor won't get called becuse the constructor was not invoked successfully. But the destructor of the class X will definitely be called and therefore the array 'r' will be deallocated. So we didn't have to care about resource deallocation at the time exceptions are raised.

Labels: ,

Ternary operator in C++

#include
using namespace std;



int main () {

cout << ( 70 >= 60 ? 40 > 50 ?"Passed" : "Failed":"56");
int x=( 70 >= 60 ? 40 > 50 ?20 : 30:40);
cout<<( 70 >= 60 ? 40 > 50 ?20 : 30:40);
cout << ( 70 >= 60 ? 40 > 50 ?"Passed" : "Failed":56); // Error .. here we cannot use different types in ternary operator output. So 56 will give an error it has to be a char*
return 0;

No other thing is important but just try to understand the structure of this operator

Labels: ,

Namespace in C++

Reference :- Name Space Tutorial

Namespaces allow to group entities like classes, objects and functions under a name. This way the global scope can be divided in "sub-scopes", each one with its own name.

Important points to remember.

1) Why is "using namespace std;" BAD ?

Well What I can gather from the information given in the article is

See this example
// using
#include
using namespace std;

namespace first
{
int cout = 5;
int y = 10;
}

namespace second
{
double x = 3.1416;
double y = 2.7183;
}

int main () {
using namespace first;
// using namespace second;
std::cout << cout; --> // Error. But if we dont use using namespace std; This code will run

return 0;
}

Here we have two namespaces defined and now we have ambiguous variables. Removing ambiguity was the main reason for using namespaces right ;)

So its better not to use using globally but rather than use it for what you require.
Nevertheless its not such a big issue in my opinion

Labels: ,

Sunday, February 24, 2008

First

Ok here i go with my prefessional blog. I would record my everyday progress here also would put on all importamt links here related to Math Finance and also some articles ..

Just some random stuff ..

Labels: