Sunday, June 28, 2009

Const variables inside a class definition



NOTE : -
THIS CONTENT IS NOT ORIGINAL

25. Const variables inside a class definition

A class variable can also be constant. That's just like static, except it is given a value inside the class declaration and that value cannot be modified:


using namespace std;
#include

class vector
{
public:

double x;
double y;
const static double pi = 3.1415927;

vector (double a = 0, double b = 0)
{
x = a;
y = b;
}

double cilinder_volume ()
{
return x * x / 4 * pi * y;
}
};

int main()
{
cout << "The value of pi: " << vector::pi << endl << endl;

vector k (3, 4);

cout << "Result: " << k.cilinder_volume() << endl;

return 0;
}


Output
The value of pi: 3.14159

Result: 28.2743





BIBILOGRAPHY / REFERENCE : - http://www.4p8.com/eric.brasseur/cppcen.html

No comments:

3G S

JAIL BREAK

iPHONE

BILL GATES

StEvE JoBs

steve jobs

STEVE JOBS

Steve Jobs

Love Country

SD

Burroughs

Lift

Joseph Johnson

Apple Rainbow

Apple Blue

Apple Laser Printer