Hi Viorel! As you can see, the I already include a copy constructor. By the way, all the CFVector3D - data members and member functions - are public, there is no private or protected!
I'm using the m_Array to work with a class called CFVector3D. I have following your idea.. but i get 2 error error from compiler:
error C2558: class 'CFVector3D' : no copy constructor available or copy constructor is declared 'explicit' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlalloc.h(292) : while compiling class-template member function 'size_t ATL::CAtlArray<E>::Add(ATL::CAtlArray<E>::INARGTYPE)' with [ E=CFVector3D ] d:\bcad_api\addinforbricscad\addinforbricscad\vectorlib\vectorlib.h(916) : see reference to class template instantiation 'ATL::CAtlArray<E>' being compiled with [ E=CFVector3D ] c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcoll.h(938) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const CFVector3D' (or there is no acceptable conversion) c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlalloc.h(292) : while compiling class-template member function 'void ATL::CAtlArray<E>::InsertAt(size_t,ATL::CAtlArray<E>::INARGTYPE,size_t)' with [ E=CFVector3D ]
Here is the CFVector3D header (a simplified version):
class CFVector3D : public IVector3D { public:
CFDouble z; CFDouble y; CFDouble x;
CFVector3D(); virtual ~CFVector3D(); CFVector3D(CFDouble X, CFDouble Y, CFDouble Z);
I think ATL requires constructors which take a constant reference. I reproduced your first error message and I solved it by adding "const" to parameter list.
So try CFVector3D::CFVector3D(const CFVector3D &rVector) instead of CFVector3D::CFVector3D(CFVector3D &rVector).
MFC CArray conversion sintax for MFC CAtlArray
MauroM
CAtlArray<CFVector3D> m_Array;
jpvalappil
As you can see, the I already include a copy constructor. By the way, all the CFVector3D - data members and member functions - are public, there is no private or protected!
I still got these errors!
Ioan
Shilps
I'm using the m_Array to work with a class called CFVector3D. I have following your idea.. but i get 2 error error from compiler:
error C2558: class 'CFVector3D' : no copy constructor available or copy constructor is declared 'explicit'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlalloc.h(292) : while compiling class-template member function 'size_t ATL::CAtlArray<E>::Add(ATL::CAtlArray<E>::INARGTYPE)'
with
[
E=CFVector3D
]
d:\bcad_api\addinforbricscad\addinforbricscad\vectorlib\vectorlib.h(916) : see reference to class template instantiation 'ATL::CAtlArray<E>' being compiled
with
[
E=CFVector3D
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcoll.h(938) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const CFVector3D' (or there is no acceptable conversion)
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlalloc.h(292) : while compiling class-template member function 'void ATL::CAtlArray<E>::InsertAt(size_t,ATL::CAtlArray<E>::INARGTYPE,size_t)'
with
[
E=CFVector3D
]
Here is the CFVector3D header (a simplified version):
class CFVector3D : public IVector3D
{
public:
CFDouble z;
CFDouble y;
CFDouble x;
CFVector3D();
virtual ~CFVector3D();
CFVector3D(CFDouble X, CFDouble Y, CFDouble Z);
CFVector3D(IVector3D* pVector);
CFVector3D(CFVector3D &rVector);
CFVector3D(SFPoint3D &rPoint);
CFVector3D& operator =(SFPoint3D &rPoint);
CFVector3D& operator =(CFVector3D &rVector);
};
and here is the class implementation:
CFVector3D::CFVector3D()
{
x=0;
y=0;
z=0;
}
CFVector3D::~CFVector3D()
{
}
CFVector3D::CFVector3D(CFDouble X, CFDouble Y, CFDouble Z)
{
x=X;
y=Y;
z=Z;
}
CFVector3D::CFVector3D(IVector3D* pVector)
{
pVector->GetXYZ(&x,&y,&z);
}
CFVector3D::CFVector3D(CFVector3D &rVector)
{
x=rVector.x;
y=rVector.y;
z=rVector.z;
}
CFVector3D::CFVector3D(SFPoint3D &rPoint)
{
x=CFDouble(rPoint.x,rPoint.xError);
y=CFDouble(rPoint.y,rPoint.yError);
z=CFDouble(rPoint.z,rPoint.zError);
}
CFVector3D& CFVector3D::operator =(CFVector3D &rVector)
{
x=rVector.x;
y=rVector.y;
z=rVector.z;
return *this;
}
CFVector3D& CFVector3D::operator =(SFPoint3D &rPoint)
{
x=CFDouble(rPoint.x,rPoint.xError);
y=CFDouble(rPoint.y,rPoint.yError);
z=CFDouble(rPoint.z,rPoint.zError);
return *this;
}
How could i avoid these two above compiler errors
Any ideea is appreciate!
Ioan
bhan
I think your CFVector3D class needs a public implicit copy constructor:
class CFVector3D
{
public:
CFVector3D(const CFVector3D & alt);
. . .
};
// . . .
CFVector3D::CFVector3D(const CFVector3D & alt)
{
x = alt.x;
y = alt.y;
z = alt.z;
}
or, since you have the "=" operator, you can re-use it:
CFVector3D::CFVector3D(const CFVector3D & alt)
{
*this = alt;
// (also change the parameter of "=" operator to "const CFVector3D &")
}
Hope it helps.
Thor Laage-Petersen
Excelent response!!
It works!
Thank you (mersi fain!) :)
Ioan
Blacata
I think ATL requires constructors which take a constant reference. I reproduced your first error message and I solved it by adding "const" to parameter list.
So try CFVector3D::CFVector3D(const CFVector3D &rVector) instead of CFVector3D::CFVector3D(CFVector3D &rVector).