Const (computer programming): Difference between revisions

Content deleted Content added
<code>volatile</code>: explained what it actually means
method example
Line 19:
 
Both are <code>char</code>s with constant value. On some implementations, using <code>const</code> on both sides of the type (for instance, <code>const char const</code>) generates a warning but not an error.
 
===Methods===
In C++, methods can be tagged as constant. Observe this example:
 
<code>
class Point
{
public:
int getX() const;
int getY() const;
void setX(int x);
void setY(int y);
}
 
void doSomethingWithAPoint()
{
const Point point(20, 30);
cout << "x = " << point.getX() << endl; // this code is legal
point.setX(50); // this statement will NOT compile, because the point contents are immutable
}
</code>
 
===Pointers and references===