Get the FREE certificate on C, C++, Java, Python, Perl, PHP, SQL, Linux & Javascript!
Home C C++ Java Python Perl PHP Spring SQL Javascript Linux

How to initialize const variables of any class in C++

#include <iostream>
using namespace std;

class circle{
	double r;
	const double pi;
	circle(double r) : pi(3.14159){
	double area (){
		return pi*(pow(r,2));
	double circumference (){
		return 2*pi*r;

int main(){
	circle c=circle(6.70);
	cout<<"area of circle :"<<c.area()<<endl;
	cout<<"circumference of circle :"<<c.circumference ()<<endl;
	return 0;