mardi 13 juillet 2021

const reference parameter with default value

I have one class with constructor that have one parameter as other struct that have default value. Something like this

class A
{
public:
A(someStruct st = someStruct::defaultStruct());
};

I've run default analizer on mu code and it says that this parameter should be const ref. But it's kinda ref to a temporary, though I'm making a copy of it the the constructor, but still I'm confused should I do it const ref.

someStruct::defaultStruct() is something like

static someStruct someStruct::defaultStruct()
{
    return { 0, 0 };
}

Aucun commentaire:

Enregistrer un commentaire