Can someone explain why i can change this immutable variable please?

Gary Willoughby dev at nomad.so
Wed Oct 9 08:26:33 PDT 2013


Can someone explain why i can change Bar's immutable name member 
please?

	import std.stdio;

	class Foo
	{
		public void change(string name)
		{
			name = "tess";
			writeln(name);
		}
	}

	class Bar
	{
		private static immutable string name = "gary";

		public void test()
		{
			auto foo = new Foo();
			foo.change(this.name);
		}
	}

	void main(string[] args)
	{
		auto bar = new Bar();
		bar.test();
	}

I thought an error would inform me that the `Foo.change` function 
is being called with the wrong parameter type.


More information about the Digitalmars-d-learn mailing list