Warning: shadow a member of this

0

I have the following problem. I need to remove all warnings from a source and there is one (I have it in several sources) that says the following, I'm using linux and cmake:

/mnt/clas/Source/CLAS/lashandle.h: In constructor ‘LAS_HeaderSectionValue::LAS_HeaderSectionValue(const QString&, const QString&, const QString&, const QString&)’:
/mnt/clas/Source/CLAS/lashandle.h:63: warning: declaration of ‘Description’ shadows a member of 'this'
/mnt/clas/Source/CLAS/lashandle.h:63: warning: declaration of ‘Value’ shadows a member of 'this'
/mnt/clas/Source/CLAS/lashandle.h:63: warning: declaration of ‘MesUnit’ shadows a member of 'this'
/mnt/clas/Source/CLAS/lashandle.h:63: warning: declaration of ‘ShortName’ shadows a member of 'this'

the .h file where the line indicates me has the following declaration / definition:

class LAS_HeaderSectionValue
{
public:
    LAS_HeaderSectionValue(const QString &ShortName, const QString &MesUnit, const QString &Value, const QString &Description)
    {
        this->m_pShortName = new QString(ShortName);
        this->m_pMesUnit = new QString(MesUnit);
        this->m_pValue = new QString(Value);
        this->m_pDescription = new QString(Description);
    }
};

Can someone help me / guide to remove that warning ?. I do not finish to understand what is happening. My code did not have this but I added them and even so it still indicates the same warning

    
asked by Emiliano Torres 20.02.2017 в 16:05
source

1 answer

2

You are omitting important information about the class. I assume that your class looks more like this:

class LAS_HeaderSectionValue
{
public:
    LAS_HeaderSectionValue(const QString &ShortName, const QString &MesUnit, const QString &Value, const QString &Description);

    QString ShortName();
    QString MesUnit();
    QString Value();
    // ...
};

The error is basically telling you that the local variables of the constructor have the same name as members of the class, which is causing a concealment of the latter.

The solution is as simple as changing the name of the constructor variables:

LAS_HeaderSectionValue(const QString &shortName, const QString &mesUnit, const QString &value, const QString &description);

BONUS TRACK

It does not make much sense that members m_pShortName and company are pointers. The class QString is responsible for guaranteeing the life cycle of the chain it stores. You'll get a cleaner, faster and more manageable code if you use QString by value:

class LAS_HeaderSectionValue
{
    QString m_ShortName;
    QString m_MesUnit;
    QString m_Value;
    QString m_Description;

public:

    LAS_HeaderSectionValue(const QString &shortName, const QString &mesUnit, const QString &value, const QString &description)
    {
        m_ShortName = shortName;
        m_MesUnit = mesUnit;
        m_Value = value;
        m_Description = description;
    }
};

Or better yet:

LAS_HeaderSectionValue(const QString &shortName, const QString &mesUnit, const QString &value, const QString &description)
  : m_ShortName(shortName),
    m_MesUnit(mesUnit),
    m_Value(value),
    m_Description(description)
{ }
    
answered by 20.02.2017 / 16:15
source