ex3-8m.cpp - Example 3-8m const member function with a mutable member

// File: ex3-8m.cpp - const member function with a mutable member

void makeit6(int& I)
{
	I = 6;
}


class ABC
{
	mutable int x;
public:
	void funk();
	void gunk() const;				// const member function
	void hunk(int&);
	void junk(int&) const;			// const member function
	void lunk(const int&);
	void munk(const int&) const;	// const member function
};

void ABC::funk() 
{
	x = 6;	
	makeit6(x);
	makeit6(6);		// error: cannot convert const int to int&
}

void ABC::gunk() const
{
	x = 6;
	makeit6(x);
}

void ABC::hunk(int &I) 
{
	x = 6;	
	makeit6(I);
	makeit6(x);
}

void ABC::junk(int &I) const
{
	x = I;
	makeit6(I);
	makeit6(x);
}


void ABC::lunk(const int &I) 
{
	x = I;	
	makeit6(I);		// error: cannot pass const int& as int& parameter
	makeit6(x);
}

void ABC::munk(const int &I) const
{
	x = I;
	makeit6(I);		// error: cannot pass const int& as int& parameter
	makeit6(x);
}


int main()
{
	ABC object;
	int i = 3;
	object.funk();
	object.gunk();
	object.hunk(i);
	object.junk(i);
	object.lunk(i);
	object.munk(i);

	return 0;
}



CIS27: Programming in C++    Instructor: Joe Bentley