B
Bart Simpson
I have the ff class decl:
class ArrayData : public myArray
{
public:
inline ArrayData(){ InitArray(&m_arr);}
inline explicit ArrayData(const std::string& name):m_name(name){
InitArray(&m_arr);}
inline explicit ArrayData(const ArrayData& arr):m_name(arr.m_name) {
CopyArray(&arr.m_arr, &m_arr) ;}
inline ArrayData& operator= (const ArrayData& rhs)
{
if (this != &rhs){ CopyArray(&rhs.m_arr, &m_arr) ; m_name = rhs.m_name ;}
return *this ;
}
inline ~ArrayData(){ FreeArray(&m_arr); }
inline const std::string& Name() const { return m_name ; }
private:
tpArray m_arr ;
std::string m_name ;
};
I also have a template class called PointerList<T>, which allows me to
manage a list of pointers generically. I made the copy/assignment ctors
for PointerList private.
I have a class (A) that uses a list of pointers of type ArrayData. I
need to implement a copy constructor for class A, and that requires a
member by member copy of the elements in the list...
I implemented this:
......
//Copy PointerList<ArrayData> items element by element
if (!rhs.m_outarray_1ist.empty())
{
PointerList<ArrayData>::const_iterator cit = rhs.m_outarray_1ist.begin();
for (cit; cit != rhs.m_outarray_1ist.end(); cit++)
{
ArrayData *arr = new ArrayData(*cit); //Barfs here
m_outarray_1ist.push_back(arr) ;
}
}
However the compiler barfs at the line where the variable is being
created, with the error message:
cannot convert parameter 1 from 'ArrayData *const ' to 'const std::string &'
class ArrayData has a copy constructor that accepts a const ArrayData&,
so why does the compiler insist on casting it to a std::string (even
though I am using the 'explicit' keyword ?
class ArrayData : public myArray
{
public:
inline ArrayData(){ InitArray(&m_arr);}
inline explicit ArrayData(const std::string& name):m_name(name){
InitArray(&m_arr);}
inline explicit ArrayData(const ArrayData& arr):m_name(arr.m_name) {
CopyArray(&arr.m_arr, &m_arr) ;}
inline ArrayData& operator= (const ArrayData& rhs)
{
if (this != &rhs){ CopyArray(&rhs.m_arr, &m_arr) ; m_name = rhs.m_name ;}
return *this ;
}
inline ~ArrayData(){ FreeArray(&m_arr); }
inline const std::string& Name() const { return m_name ; }
private:
tpArray m_arr ;
std::string m_name ;
};
I also have a template class called PointerList<T>, which allows me to
manage a list of pointers generically. I made the copy/assignment ctors
for PointerList private.
I have a class (A) that uses a list of pointers of type ArrayData. I
need to implement a copy constructor for class A, and that requires a
member by member copy of the elements in the list...
I implemented this:
......
//Copy PointerList<ArrayData> items element by element
if (!rhs.m_outarray_1ist.empty())
{
PointerList<ArrayData>::const_iterator cit = rhs.m_outarray_1ist.begin();
for (cit; cit != rhs.m_outarray_1ist.end(); cit++)
{
ArrayData *arr = new ArrayData(*cit); //Barfs here
m_outarray_1ist.push_back(arr) ;
}
}
However the compiler barfs at the line where the variable is being
created, with the error message:
cannot convert parameter 1 from 'ArrayData *const ' to 'const std::string &'
class ArrayData has a copy constructor that accepts a const ArrayData&,
so why does the compiler insist on casting it to a std::string (even
though I am using the 'explicit' keyword ?