Using the const and volatile variable in C++ program
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info:
To do: Declaring and using the const and const volatile in C++ program
To show: The const and volatile keyword usage in C++ program to declare the const volatile variable
// Demonstrates the type casting
#include <iostream>
using namespace std;
class One
{
public:
void funct()
{cout<<"Testing..."<<endl;};
};
// const and volatile...
const volatile int* Test1;
// const...
const int* Test2;
void TestConstVol()
{
One Test3;
// remove const...
const_cast<One>(Test3).funct();
// remove const and volatile...
const_cast<int> (Test1);
}
int main(void)
{
TestConstVol();
return 0;
}
Output example:
Testing...
Press any key to continue . . .