/************************************************************************** * * Language: C++ * Purpose: Program to demonstrate the 'new' statement. * Author: M J Leslie * Date: 27-Sep-98 * * Initialise a constant within a class. * **************************************************************************/ #include <iostream.h> // For cout. class Math { public: // Constructor contains the definition of PI. Math() : PI(3.142) {} ~Math() {} float Diameter (float Radius) { return (Radius * PI); } private: // Declare PI. We can not assign a value here. const float PI; }; main() { Math Formula; float Radius = 5; cout << " Radius is " << Radius << endl; cout << " Diameter is " << Formula.Diameter(Radius) << endl; }
file: /Techref/language/ccpp/cppref/EXAMPLES/const1.cc, 0KB, , updated: 1998/9/27 12:50, local time: 2024/8/14 21:31,
18.188.195.193:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://techref.massmind.org/techref/language/ccpp/cppref/EXAMPLES/const1.cc"> language ccpp cppref EXAMPLES const1</A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to techref.massmind.org! |
.