Re: Do I need a singleton here? RESOLVED
"Luc Danton" <lucdanton@free.fr> wrote in message
news:4cc11cd9$0$8058$426a74cc@news.free.fr...
On 22/10/2010 07:00, Jim Langston wrote:
I just tried it out and it seems that in Express 2010 anyway my concern
was justified. Without an operator=(&&) this will not compile (as it
shouldn't).
world.fonts[L"Normal"] = jmlGL::jglFont( hDC, L"Courier New", 24 );
error C2248: 'jmlGL::jglFont::operator =' : cannot access private member
declared in class 'jmlGL::jglFont'
However, when I add
jglFont& operator=(jglFont&& rhs) { /*.real code here..*/ }
my program compiles and runs. I did not have to use std::move.
But jglFont is your type, so the expression jmlGL::jglFont( hDC, L"Courier
New", 24 ) is a constructor call that results in an rvalue of this type,
right?
What you need to check is:
jglFont lval = /* whatever */;
jglFont destination; /* or another init if not DefaultConstructible */
destination = lval;
You are correct. This will not compile:
world.fonts[L"Normal"] = world.fonts[L"Bold"];
error C2248: 'jmlGL::jglFont::operator =' : cannot access private member
declared in class 'jmlGL::jglFont'
Okay. I think I understand. If the object being assigned from is a
temporary operator=(&&) will be called. If it's not a temporary then
operator=(&) will be called.