Q1. from // line 1, i see that is a destructor. but why virtual ? virtual is usued in inheritance .why in a class defunition ? is it just a syntax ?
You really need virtual functions whenever the class will be used as base class(the rule is if the class has any other virtual function, add the virtual destructor) . Fortunatly, the compilers I've used are able to flag this as a warning.
The reason why you need a virtual destructor is shown by this code
Code:
#include <iostream>
using namespace std;
class A {
public:
virtual void a() { cout << "A" << endl; }
// no virtual destructor
};
class B {
int* items;
public:
B() : items(new int[100]) { }
~B() { delete[] items; }
virtual void a() { cout << "B" << endl; }
};
int main()
{
A* a = new B;
delete a; // since a's destructor is not virtual, A's destructor is called not B's
return 0;
}
b.A :: func1() // is it legal ? what does it mean ? //line 2
I don't think so.