// -----------
// Methods.c++
// -----------
#include <cassert> // assert
#include <iostream> // cout, endl
class A {
private:
static int c;
int i;
mutable int j;
public:
A (int i) :
i (i),
j (0)
{}
~A ()
{}
static void f () {
++c;
// ++i; // doesn't compile
// ++j; // doesn't compile
// g(); // doesn't compile
// h(); // doesn't compile
// A* p = this; // doesn't compile
}
void g () const {
++c;
// ++i; // doesn't compile
++j;
f();
// h(); // doesn't compile
// A* p = this; // doesn't compile
const A* q = this;}
void h () {
++c;
++i;
++j;
f();
g();
A* p = this;
const A* q = this;}};
int A::c;
int main () {
using namespace std;
cout << "Methods.c++" << endl;
A::f();
{
A x(2);
A::f();
x.f();
}
A::f();
{
A x(2);
// A::g(); // doesn't compile
x.g();
// A::h(); // doesn't compile
x.h();
}
{
const A x(2);
// A::g(); // doesn't compile
x.g();
// A::h(); // doesn't compile
// x.h(); // doesn't compile
}
cout << "Done." << endl;
return 0;}
syntax highlighted by Code2HTML, v. 0.9.1