Archive for the ‘study’ Category

c/c++ :: conversion constructor

Monday, June 21st, 2004

A constructor with only one argument acts like a conversion function. It helps conversion of argument to class type and therefore called conversion constructor.

Example -

class A{ // some class
public:
A(int); // conversion constructor
}

the following are valid, and the conversion constructor is called for each of them

int myint1 = 1, myint2 = 2, myint3 = 3, myint4 = 4;
A a= myint1; // conversion
A b(myint2); // normal constructor using one argument.
A c = A(myint3); // normal constructor using one argument.
c = myint4; // conversion

Note that

A a;

is invalid , but

A a = myint1;

is valid. (Assuming that no A( void ) constructor is there.)

Doubt : Do you observe that constructor is called twice on c in the example above. First normal constructor and then the conversion constructor. Something fishy. Right? What say you ?

Modified : May 18th, 05 : Made more readable, seeing high rank on google search.

c++ :: polymorphism

Sunday, June 20th, 2004

/** \brief
*.Polymorphism
*.- given identical instructions, should take different actions
*.- call to a member function will cause a different function.
*. to be executed depending on the type of object that invokes the function
*.- implemented using _virtual_
*. if i don’t give virtual, polynmorphism doesnot happen
*. and always the code of base class will be executed.
*. make the function virtual and declare it in the body of derived class
*.- descision of which functuion to call is made at run time.
*. called late/dynamic binding. overhead (upto 10% slower)
*.- early/static binding - the normal way
*.- only work with pointers [see in main.cpp]
*
*.Only a virtual function can be made abstract (=0)
*.Only functions can be virtual, class/variables cannot be
*.`virtual’ can only be specified for functions
*
*.Virtual function of base class can be called using scope resolution
*.eg Base::method();
*
*.Constructor cannot be virtual.
*.Destructors should be virtual. _imp_
*.- it handles the deletion of the derived class and base class (in order)
*
* pure virtual function (abstract)-
* definition with =0
* - pure virtual function can have a body
*.
* - Once one function in a class is virtual, there’s no additional
* overhead to making other functions virtual because as soon as one
* function is virtual, a virtual table is added to every object.
* Thus it doesn’t cost you much to follow the rule of making the
* destructor virtual in any class with virtual functions.
*.
* abstract class -
* a class with atleast one function pure virtual
* -cannot declare an object of a class if the class is abstract
* -can’t write a function call that passes or returns an object of abstract class
* eg void invalidFunc( abstractClass ) or abstractClass invalidFunc
* because this results in creation of object and therefor can’t do so
*/

os class for placements prepration

Wednesday, June 16th, 2004

just a surprise class for me. i was not prepared at all. just did some bc there. anyway it went fine. it was mainly unix oriented.

static (.a) vs shated (.so) library . how do i create a shared library ? find out. create a mailing list or df for placements prepration. i am not sitting for
placements, but learning all these things is good. hmmm.

today i and nir are setting up dns at 36.10. good hmmm…

ok bye!!!

yooo i did it

Friday, May 21st, 2004

i got the basic fundas of hierarchy in glperformer.
i will write a small tutorial for other helpless souls struggling with pf.
there is still some problem with the hierarchy like what can be child of what. i hope to sort it out soon. i have to finish my acg assignment asap.
then start vision and acg project work. and the summer work. i have to talk to pjn sir about that.