question about ref keyword

Jack jckj33 at gmail.com
Thu Mar 18 16:59:24 UTC 2021


let's assume this class:

class C
{
	private S m_s;

	this()
	{
		m_s = S(30);
	}

	ref S value() { return m_s; }
	ref S value(ref S s)
	{
		return m_s = s;
	}
}

and I do something like this:

	auto s1 = S(40);
	auto c = new C();
         c.value = s1;
	s1.n = 80;


give that value has ref in its signature, the s1 is passed as a 
"pointer" right? also, when I do: m_s = s; m_s is a copy of s1 or 
a reference to it? setting s1.n to 80 in the next line doesn't 
seem to change c.value so it seems it passed s1 as a pointer but 
when it comes to assignment a copy was made?


More information about the Digitalmars-d-learn mailing list