Wednesday, August 11, 2010

Overriding overloaded methods

#include <iostream>

using namespace std;

class B {
    public:
    virtual void A(string a, int b) {
        cout<<"B::A(string, int)"<<endl;
    }
    virtual void A(int c) {
        cout<<"B::A(int)"<<endl;
    }
};

class D : public B {
    public:
    virtual void A(string a, int b) {
        cout<<"D::A(string, int)"<<endl;
    }
};

int main() {
    D d;
    B* b = &d;
   
    b->A("a", 1);
    b->A(2);
   
    d.A("a", 1);
    d.A(2);

    return 0;
}

What do you think would be output of the above code?

Obviously, the output is not what most people will expect i.e.:
D::A(string, int)
B::A(int)
D::A(string, int)
B::A(int)


The code will instead give compilation error on line
     d.A(2);

This is because if you override one overloaded method, you need to override all of them, otherwise the ones you don't override are not available in the derived class.

To get things working you'll need to add following method in class D


virtual void A(int c) {
    B::A(c); 
}

As suggested by Kapil in the comments, the correct and elegant way to get it working is to add a declaration of A() in classD:

using B::A;

Monday, July 19, 2010

Domestication

I look in the mirror,
I look around,
I see the wildness tamed,
The jungles are lost,
The animals are gone,
all that is left are sanctuaries,
domestication taught in the name of education.

Friday, June 18, 2010

The biggest delusion of all times is time itself

Time was invented to sequence events, to record what happened first, and what after that. Just like a label. We never realized when time took control of our lives. Things went wrong when we thought of time as an absolute entity, shared by everything and everyone. Is time really same for everyone?

As I see, time is not same for everyone. Putting it simply: when speed (w.r.t. clock time) of some action gets slow, it's because of its time getting slow! Assuming time is absolute makes many thing simpler, looking it the other way can explain things which otherwise have no satisfactory answers.

When you are feeling bored lazy, your time goes fast, you spend like an hour while your watch shows that only 15 minutes have passed. Similarly when you are excited, enjoying, your time goes slower. No doubt being happy makes you live longer i.e. with respect to the clock time.

Some people seem to age faster, others look younger just because their time passes at different rate.

Some people can solve problems quickly, because their time passes fast. While you think they solved the problem in seconds they actually took a minute of "their time" to solve it.

Oh, by the way, if you have realized I just discarded "Time Travel" concept as viewed by most of us :).

Wednesday, April 7, 2010

Predefined or a matter of chance but not a choice!

Life is predefined or a matter of chance but not a choice. I have used this 'funda' many time. The best thing about this 'funda' is that the other person is left baffled. They obviously can't agree to such a thing and eehh at the same time they can't really disagree :D.

How do people do something? They do some action: blink eyes, move hands, speak etc. How do people do some action? They move some muscle in their body which results into action. How do muscle move? They get signals from brain. How do muscle get signals from brain? Chemical reactions! How does a brain thinks? Again chemical reactions. You can not deny the fact that every thing that happens in our body is result of some chemical reactions. Everything happening around us is a result of some chemical reactions.

Consider this: for a given condition, keeping everything fixed; the temperature, the pressure and everything else, will a chemical reaction produce exactly same products every time?

If you think that the answer is 'YES', then your life is nothing but a chain reaction. At any instant the present conditions are product of the previous reactions, which were product of previous reactions and so on till the 'start of time' when the first reaction took place. No matter what you do, or think to do, its all part of the game. Nothing could have happened except what happened. You have no control on what's happening.

If you think your answer to the question is 'NO', then your life is just a matter of chance. Since all the conditions remain same there can not be a logic as to determine what would be the products of a reaction. It has to be random. Everything you do or happening around is result of random reactions. You again have no control on what's happening.

Whether its predefined or a matter of chance life is surely not a choice.

Sunday, March 14, 2010

Right or Wrong??

Recently I came to know that many things I say or write sound daft and confuse people, so please don't mind if what follows doesn't makes any sense... :P 

What do you think... things are going the right way or the wrong way?
I'll tell you what I believe. It doesn't matters! Really, according to me it doesn't matters whether things are going the right or the wrong way; if you just believe that things are going the right way..rest everything will be fine :-)

Why so??

There are two things, first: your thinking that things are going right or wrong, and second: whether things are actually going right or wrong. Let us consider all four cases in detail:

o You think that things are going right, and things are actually going right:
Things are actually going right implies that your thinking must be correct, and you are thinking that things are going right, this complies with the original statement that things are going right.
(I did warn about my thoughts sounding daft)

o You think that things are going right, and things are actually going wrong:
Things are actually going wrong implies that your thinking must be incorrect, and you are thinking that things are going right. This means that things must not be going right, this again complies with the original statement that things are going wrong.

o You think that things are going wrong, and things are actually going right:
Things are actually going right implies that your thinking must be correct, and you are thinking that things are going wrong. This means that things must not be going right! oops.. now there is a contradiction with the original statement that things are actually going right.

o You think that things are going wrong, and things are actually going wrong:
Things are actually going wrong implies that your thinking must be incorrect, and you are thinking that things are going wrong. This meas that things must be going right! once again we have a contradiction with the original statement that things are actually going wrong.

Now you can see, if you think that everything is going the right way, you don't get any contradictions, if you think that things are going the wrong way then you always get contradictions in life. Contradiction means things in life don't fit together and you tend to feel even more that something is wrong which sure doesn't give you peace of mind. So, it doesn't even matters whether things are going the right way or the wrong way, if you think and feel that the right things are happening, everything will start to fall in place and fit together.




Thursday, November 26, 2009

Status messages

Some of my status messages...

  • When man learns to look deep inside others, he learns to forgive.
  • Everyone has a talent but the real talent is to control it.
  • Some people just live to die while some others are dying to live.
  • May be you'll win, but you see, I can't lose now.
  • Common man is a waste produced by friction between powerful people.
  • When u look yourself close enough, you don't see problems.. you see there is nothing to fix.
  • If whole mankind was to be described by a single word, it would be 'stupid'.
  • Our leaders fought for freedom and all they got was independence!
  • It really pains sometimes, most of the other times pain is just an imagination.
  • Are we really living or someone is playing SimCity up there?
  • Many mornings I wake up and think "When was the last time I slept?" 
  • God doesnt need to be pleased or made happy. Just embrace the Power with all heart. Be a part of it, be God.
  • No doubt everyone is unique, the problem is 99% of people are unique only in 1% of aspects. 
  • A good life is when you don't have to think about whether its a good life or not. 
  • Try being good and happiness runs away from you. Be good and happiness will follow you. I guess I'm still trying 
  • Knowledge makes life difiicult. If you don't know there is a tiger under you bed you'll sleep calmly. If you know there is a harmless tiger under your bed, you just can't sleep 
  • Even the ugliest truth is beautiful. No matter how painful, it provides solace to soul.
  • Sinners are potential saints - Swami Vivekananda 
  • Two things drive a man, his family and his dreams. Give him a good family and respect his dreams and you'll get the best out of him.
  •  Everyone has something boring to talk about. When you find someone who is not boring at all, you know you are in love. 
  • May be the world will take me away from myself, but it can't take away my thoughts.. my dreams for they don't belong to this world. 
  • They planned, planned and planned and He smiled for it was all His plan. 
  • We are all defective pieces. Love is when two defective pieces fit into each other.
  • There is already a machine on my desk, don't want another one on my chair.
  • Don't say sorry or thanks till its really needed or it'll stop having any meaning. 
  • Killing is not really a sin, enjoying the killing is.
  • I'm nothing but ashes.... a phoenix will rise again
  • Many a times I don't want to be myself... but there are no better options.
  • I don't hate myself, its just I am what I hate.
  • Brilliance and madness are two sides of the same coin
  • Money is not the only source of happiness, but its sure one of the best ones.
  • You don't need a medical certificate to be mad... just be yourself. 
  • People people everywhere, trying to make a living, are they really living??  
  • Dilbert makes me feel better
  • Behind every man there is a woman, and its upto her to make him successful or devastate him.
  • I'm not a bad guy, just tired being a good guy.
  • Be careful what you ask for, you might get it.
  • Part1--If you can convert your thoughts into other's feelings, you are one of those who rules this world. Part2--What you feel are actually the thoughts of those who have been ruling this world. (agam)

Saturday, September 19, 2009

Does Earth revolves aroud Sun ??

Warning: I am no astronomer or a researcher. Everything below are my random thoughts :P

Does Earth revolves around Sun? Or is it the other way round? Yeah... I know Galileo told this four centuries ago that its Earth that revolves around Sun, but this doesn't means that I can't raise a doubt.. :D :P.

It was around two months back when I was working in my office and this popped into my head. I pinged my colleagues to know their opinion and it was declared that I was getting mad [eh eh eh]. Anyway, back to the point: does Earth really revolves around Sun? Me and everyone else has been taught this in school. But I remember reading another thing, that if two bodies are in motion then both of them are revolving around each other. So, when you say which one is revolving around the other one, it totally depends on the frame of reference. With respect to Earth's frame of reference isn't it absolutely correct that Sun, Moon and all other celestial bodies are revolving around Earth?

Just a thought, may be Sun and Earth are revolving around the combined center of mass (you can extend this for all planets). The center of mass would be closer to Sun so, its revolving in a small circle and the Earth is revolving in a bigger circle. So, when you look from the reference frame of one you can see the other revolving in an elliptical orbit!

Yeah, this all may not make any sense, but it just came back to my mind.. so I thought to put it down..