How can correctly use this ‘+=’ function if the function is declared within a namespace?
namespace WinFile
{
std::stack <tstring> operator += ( std::stack <tstring>& s1, std::stack <tstring> s2 )
{
// Post:
if ( s1 == s2 )
{
return s1;
}
while ( !s2.empty() )
{
s1.push( s2.top() );
s2.pop();
}
return s1;
}
}
Now how do I use this function (without saying using namespace WinFile):
std::stack <tstring> s1;
std::stack <tstring> s2;
// ...after adding some values to the stacks
s1 += s2; // this gets a compile error
s1 WinFile::+= s2 // this says its invalid to have a ':' infront of a +=
As already suggested you can use a “using” clause:
or
or you can use the function directly with the following code:
None of which are particularly ideal, but there are no other ways, to my knowledge, to do it.