tags:

views:

90

answers:

3

I need help in understanding the following c++ code (in a .h file):

bool setFontDescription(const FontDescription& v)
    {
        if (inherited->font.fontDescription() != v) {
            inherited.access()->font = Font(v, inherited->font.letterSpacing(), inherited->font.wordSpacing());
            return true;
        }
        return false;
    }

What does 'Font(..)' means? Font is a c++ class. so Font(...) means new Font()? or create a Font object in Stack?

Thank you.

+3  A: 

It means create a Font on the stack, then assign that new Font to the access()->font variable. The Font on the stack is destroyed when that setFontDescription returns destroyed when the assignment is done.

Chris H
Generally speaking, temporaries are destroyed at the end of the full expression. (A full expression is one that isn't part of some other expression.)
sbi
+4  A: 

Create a Font object on stack, as a temporary. The object's scope is the line where it's created.

Seva Alekseyev
A: 

Can someone plz make me understand what would be the use of such an assignment?

I had a different interpretation of this. I thought 'font' already has an object which is not 'v' itself. The new temparory will be created and then the value of this temparory will be copied to what 'font' is pointing to by a call to overloaded operator =(). Is my interpretation wrong?

softice
new Font object is created and its value is assigned to ...->font. if there is no problems with assignment operator (I mean operator properly copies values of members of Font class) and ...->font is not a pointer everything should be ok with it and it should contain FontDescription v which was passed as an function argument not default or previous value.
grapkulec