Friday, July 14, 2006

c++ questions .

abstract class: have pure virtual function inside.
How can a member function in my derived class call the same function from its base class? Use Base::f();
When should my destructor be virtual? 1. if someone will say new Derived, where Derived is derived from base class,2. You do a delete p. 3.where the actual object's type is Derived but the p's type is base class.
class Sample {
public:
void f();
virtual void vf();
};

class Derived : public Sample {
public:
void f();
void vf();
}

void function()
{
Derived d;
Sample* p = &d;
p->f(); // sample::f
p->vf(); // Derived::vf
}

void function()
{
Sample* p = new Derived;
delete p; // need virtual de-constructor
}


What is a "virtual constructor"?

No ;
#include
main()
{
while((printf("Look, no semicolons!"),0){}
}
or while(!(printf("hello world"))){}
or if (printf("hello world"))
or if (printf("hello world")) {}


Checking for powers of two
int powerOfTwo(unsigned int x)
{
return !((x-1) & x);
}


Is the default constructor for Fred always Fred::Fred()? No, A "default constructor" is a constructor that can be called with no argument, it can be no parameters or take arguments by given default values.

No comments:

Post a Comment