Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void someType::somefunc();
- void MyFunc()
- {
- someType A(4); //
- Fling(A.m_val);
- A.someFunc();
- Flong(A.m_val);
- }
- class Test
- {
- public:
- Test (int value) : m_value (value)
- {
- }
- void SetValue (int value) const
- {
- const_cast <Test&>(*this).MySetValue (value);
- }
- int Value () const
- {
- return m_value;
- }
- private:
- void MySetValue (int value)
- {
- m_value = value;
- }
- int
- m_value;
- };
- void modify (const Test &test, int value)
- {
- test.SetValue (value);
- }
- void main ()
- {
- const Test
- test (100);
- cout << test.Value () << endl;
- modify (test, 50);
- cout << test.Value () << endl;
- }
- 100
- 50
- volatile const
- #include <iostream>
- using namespace std;
- void swap (const int &a, const int &b)
- {
- int
- c = a;
- const_cast <int&>(a) = b;
- const_cast <int&>(b) = c;
- }
- void main ()
- {
- const int a = 10;
- const int b = 20;
- int c = 30;
- swap (a,b);
- cout << "a = " << a << endl;
- cout << "b = " << b << endl;
- swap (c,b);
- cout << "b = " << b << endl;
- cout << "c = " << c << endl;
- }
- a = 10;
- b = 20;
- b = 20;
- c = 10;
- void f(Type dont_modify); // or
- void f(Type const& dont_modify);
Add Comment
Please, Sign In to add comment