Wednesday, May 19, 2010

A perfect example to understand constructors and destructors

#include
using namespace std;

int c = 0;
int d = 0;

struct X {
    int i;
    X(int j = 0) : i(j) { c++; }
    ~X() { d++; }
};
 
int main(){

cout<
X x1;   
cout<
    {
    X x2;
    cout<
        {
        X x3;
        cout<
        cout<
        }
        cout<
    }
    cout<

return 0;
}

 

Tuesday, May 18, 2010

Goa trip - Day 1

My last trip to Goa as a student should actually pack only two other BITSKK......Gians(leave it! anything can be appended in between) venu and lvk. The shape and shakal of the trip got changed when my colleages at my PS got added as kalavar kings to the pack. All the important changes got pitched only on the eve of the journey, which brought some more smiles on my face. Nver thought I would be part of a trip with one of the seniors members of a company, at such an young age. Always scared of the consequences that may shed gloomy shades of colors on the impression that I had portaied, in them. With fingers crossed and unstable mind and a so called blue print(which consisted of a hand drawn GOA map and list of some pubs) we started our trip.

As usual my journey started of with the waiving hands of my parents, for whom I'm a guy who has all the great qualities of Lord Rama, infact more than what he possess. So, there was always a guilty feeling in my mind, which hunts me forever, infact my lonely companion at all times. Colleages laughed at me for bringing my parents to the bus stop, but they dont know, it's involuntary. First glance at the bus shocked me. It was almost like a SETWIN bus(infact much smaller than that). For the first minute I thought WTF!!IS THIS THE BUS WHICH COSTED ME 960 FOR A JOURNEY OF 12 HRS. But, GOD always has a soft corner on me, here too. We found out that this bus is going to suffocate us only till the out-skirts of the most polluted and amicable city, HYDERABAD.

As soon as we reached Mehdipatnam, we had a glance at the huge MULTI-AXLE VOLVO."Wah!! Kya Gaadi Hai!!" Looking at it I thought the journey is gonna be more fun than all da bus journey's dat I ever did. As soon as we reached ZEDCHERLA, cleaner called us to have dinner, as if it was his hotel. After having two ZaffaNaZaffadas(ZZ), even dal tasted like the glorious "Chicken Pot Pie IX(Dont ask me what dis is)". Then the action started. I closed my eyes, tried to levitate, then to meditate, which finally ended up as a sound sleep for 12 hrs. I never thought Goa is just a eye blink away from Hyderabad.

End Of First Day

GOA trip-Day1

My last trip to Goa as a student should actually pack only two other BITSKK......Gians(leave it! anything can be appended in between) venu and lvk. The shape and shakal of the trip got changed when my colleages at my PS got added as kalavar kings to the pack. All the important changes got pitched only on the eve of the journey, which brought some more smiles on my face. Nver thought I would be part of a trip with one of the seniors members of a company, at such an young age. Always scared of the consequences that may shed gloomy shades of colors on the impression that I had portaied, in them. With fingers crossed and unstable mind and a so called blue print(which consisted of a hand drawn GOA map and list of some pubs) we started our trip.

As usual my journey started of with the waiving hands of my parents, for whom I'm a guy who has all the great qualities of Lord Rama, infact more than what he possess. So, there was always a guilty feeling in my mind, which hunts me forever, infact my lonely companion at all times. Colleages laughed at me for bringing my parents to the bus stop, but they dont know, it's involuntary. First glance at the bus shocked me. It was almost like a SETWIN bus(infact much smaller than that). For the first minute I thought WTF!!IS THIS THE BUS WHICH COSTED ME 960 FOR A JOURNEY OF 12 HRS. But, GOD always has a soft corner on me, here too. We found out that this bus is going to suffocate us only till the out-skirts of the most polluted and amicable city, HYDERABAD.

As soon as we reached Mehdipatnam, we had a glance at the huge MULTI-AXLE VOLVO."Wah!! Kya Gaadi Hai!!" Looking at it I thought the journey is gonna be more fun than all da bus journey's dat I ever did. As soon as we reached ZEDCHERLA, cleaner called us to have dinner, as if it was his hotel. After having two ZaffaNaZaffadas(ZZ), even dal tasted like the glorious "Chicken Pot Pie IX(Dont ask me what dis is)". Then the action started. I closed my eyes, tried to levitate, then to meditate, which finally ended up as a sound sleep for 12 hrs. I never thought Goa is just a eye blink away from Hyderabad.

End Of First Day

Friday, May 7, 2010

Multiple inheritence

This was the question asked to me during an interview. What all languages support multiple inheritence?
The answer is:


The definition of the Title is simple and self explanatory. BTW all this info is from: http://en.wikipedia.org/wiki/Multiple_inheritance.


Languages that support multiple inheritance include: Eiffel, C++, Dylan, Python, Perl, Perl 6, Curl, Common Lisp (via CLOS), OCaml, Tcl (via Incremental Tcl)[1], and Object REXX (via the use of mixin classes).

Diamond problem:

 Multiple inheritance allows a class to take on functionality from multiple other classes, such as allowing a class named StudentMusician to inherit from a class named Person, a class named Musician, and a class named Worker. This can be abbreviated StudentMusician : Person, Musician, Worker.

Ambiguities arise in multiple inheritance, as in the example above, if for instance the class Musician inherited from Person and Worker and the class Worker inherited from Person

C++ requires that the programmer state which parent class the feature to use should come from i.e. "Worker::Person.Age". C++ does not support explicit repeated inheritance since there would be no way to qualify which superclass to use (see criticisms). C++ also allows a single instance of the multiple class to be created via the virtual inheritance mechanism (i.e. "Worker::Person" and "Musician::Person" will reference the same object).


Thursday, May 6, 2010

Arrays

Using an int** for an array of arrays is incorrect and produces wrong answers using pointer arithmetic.

for more details:
http://bytes.com/topic/c/insights/772412-arrays-revealed