O
Ondrej Spanel
I defined operator = using template member function for a template class.
However compiler failed to recognize it is defined and created its own
version (which was member-wise copy, and a result was disastrous and hard to
debug bug, as pointer was copied).
Adding explicit operator = helped. See code snip below.
I am not sure if this compiler behaviour is standard conformant or not. Any
thoughts?
Regards
Ondrej
--
---------------------------------------
Ondrej Spanel
Lead Programmer
Bohemia Interactive Studio
www.bistudio.com
www.flashpoint1985.com
----------------------------------------------------------------------------
---
template<class Type, class Allocator=MemAllocD>
class AutoArray
{
Type *_data;
int _size;
....
public:
/// template "operator ="
template <class AnotherAllocator>
void operator = ( const AutoArray<Type,AnotherAllocator> &src )
{
... deep copy of _data array
}
/// explicit "operator =" - class does not compile well without it
void operator = ( const AutoArray &src )
{
... deep copy of _data array
}
};
void Foo()
{
AutoArray< SomeTemplate<SomeClass> > a;
AutoArray< SomeTemplate<SomeClass> > b;
b = a; /// bad code generated when explicit "operator =" not defined.
}
However compiler failed to recognize it is defined and created its own
version (which was member-wise copy, and a result was disastrous and hard to
debug bug, as pointer was copied).
Adding explicit operator = helped. See code snip below.
I am not sure if this compiler behaviour is standard conformant or not. Any
thoughts?
Regards
Ondrej
--
---------------------------------------
Ondrej Spanel
Lead Programmer
Bohemia Interactive Studio
www.bistudio.com
www.flashpoint1985.com
----------------------------------------------------------------------------
---
template<class Type, class Allocator=MemAllocD>
class AutoArray
{
Type *_data;
int _size;
....
public:
/// template "operator ="
template <class AnotherAllocator>
void operator = ( const AutoArray<Type,AnotherAllocator> &src )
{
... deep copy of _data array
}
/// explicit "operator =" - class does not compile well without it
void operator = ( const AutoArray &src )
{
... deep copy of _data array
}
};
void Foo()
{
AutoArray< SomeTemplate<SomeClass> > a;
AutoArray< SomeTemplate<SomeClass> > b;
b = a; /// bad code generated when explicit "operator =" not defined.
}