The next example is a little bit complicated, but it shows exactly the problem:
example.h:
#pragma once
class Deformation
{
public:
Deformation();
~Deformation();
private:
int m_deformationLevel;
};
namespace airplane {
namespace crashs {
class Grounding
{
class Deformation;
public:
Grounding();
~Grounding();
const Grounding& operator=( const Grounding& assign );
public:
int getVictimCount() const;
private:
int m_victimCount;
};
class Grounding::Deformation
{
public:
Deformation();
Deformation( const Deformation& copy );
~Deformation();
const Deformation& operator=( const Deformation& assign );
int getStrength() const;
private:
int m_strength;
};
}
}
example.cpp:
#include "example.h"
Deformation::Deformation()
{
}
Deformation::~Deformation()
{
}
namespace airplane {
namespace crashs {
Grounding::Grounding()
{
}
Grounding::~Grounding()
{
}
const Grounding& Grounding::operator=( const Grounding& assign )
{
m_victimCount = assign.m_victimCount;
return assign;
}
int Grounding::getVictimCount() const
{
return m_victimCount;
}
Grounding::Deformation::Deformation()
{
}
Grounding::Deformation::Deformation( const Deformation& copy )
{
}
Grounding::Deformation::~Deformation()
{
}
const Grounding::Deformation& Grounding::Deformation::operator=( const Deformation& assign )
{
// HERE! try scope of "assign".
m_strength = assign.m_strength;
return assign;
}
int Grounding::Deformation::getStrength() const
{
return m_strength;
}
}
}
Go to the implementation file, to the place maked with "HERE!" and type in a new line "assign." and look to the suggestions you get.
You should get the attributes from the class "::airplane::crashes::Grounding::Deformation", but you get the attributes from the class "::Deformation". Thats wrong, and not only a very rare case.
If you use a Library which is declaring many classes in the global namespace, and you use namespaces and subclasses to avoid naming clashes, then always if you "solve" a conflict by using a private subclass (e.g. Action) you hve this problem.
In my case, I get conflicts with windows classes/enums like "Action".