It can be initialized as in the below example using initialization list.
// Sample.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <conio.h>
using namespace std;
class CTriangle
{
public:
CTriangle();
const float m_fPi;
};
CTriangle::CTriangle():m_fPi(3.14)
{
//constructor
}
int main()
{
CTriangle obj;
cout<<obj.m_fPi;
getch();
return 0;
}
No comments:
Post a Comment