🔒 Locked
STL problem
Advertisement
Original Post
Here's what i got ClassXYZ a; std::vector alist; alist.push_back(a); it gives me this error : c:\program files\microsoft visual studio\vc98\include\xutility(39) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'const class CShape' (or there is no acceptable conversion) c:\program files\microsoft visual studio\vc98\include\vector(170) : see reference to function template instantiation 'void __cdecl std::fill(class CShape *,class CShape *,const class CShape &)' being compiled Error executing cl.exe. Thanks in advance
thanks ,
This is the definition of CShape class:
class CShape
{
public:
CShape();
~CShape();
float s_ret_w();
float s_ret_h();
float s_ret_d();
V3_s s_ret_min();
V3_s s_ret_max();
V3_s s_ret_center();
int s_ret_NOF_CP();
void s_initialize();
std::vector s_returnCP();
bool ed_isSelected();
void ed_MoveCenterTo(V3_s inC,int inView);
void ed_start(V3_s vStart,int inView,int inSType);
void ed_continue(V3_s vContinue,int inView);
void ed_end(V3_s vEnd,int inView);
int r_ret_NOF_V();
private:
void s_calc_h();
void s_calc_w();
void s_calc_d();
void s_calc_dim();
void s_calc_min();
void s_calc_max();
void s_calc_minmax();
void s_calc_center();
void s_initializeBOX();
int m_SType;
float m_w;
float m_h;
float m_d;
V3_s m_Vmin;
V3_s m_Vmax;
int m_NOF_CP;
V3_s m_Center;
std::vector m_CP;
void ed_GenerateShape(int inView);
bool m_ed_selected;
V3_s m_ed_vStart;
V3_s m_ed_vEnd;
int m_r_NOF_V;
bool m_r_renderable;
};
Constructor only calls initialization functions wich sets member variable values to default...
And this code causes the error ...
CShape a;
std::vector al;
al.push_back(a);
This is the definition of CShape class:
class CShape
{
public:
CShape();
~CShape();
float s_ret_w();
float s_ret_h();
float s_ret_d();
V3_s s_ret_min();
V3_s s_ret_max();
V3_s s_ret_center();
int s_ret_NOF_CP();
void s_initialize();
std::vector
bool ed_isSelected();
void ed_MoveCenterTo(V3_s inC,int inView);
void ed_start(V3_s vStart,int inView,int inSType);
void ed_continue(V3_s vContinue,int inView);
void ed_end(V3_s vEnd,int inView);
int r_ret_NOF_V();
private:
void s_calc_h();
void s_calc_w();
void s_calc_d();
void s_calc_dim();
void s_calc_min();
void s_calc_max();
void s_calc_minmax();
void s_calc_center();
void s_initializeBOX();
int m_SType;
float m_w;
float m_h;
float m_d;
V3_s m_Vmin;
V3_s m_Vmax;
int m_NOF_CP;
V3_s m_Center;
std::vector
void ed_GenerateShape(int inView);
bool m_ed_selected;
V3_s m_ed_vStart;
V3_s m_ed_vEnd;
int m_r_NOF_V;
bool m_r_renderable;
};
Constructor only calls initialization functions wich sets member variable values to default...
And this code causes the error ...
CShape a;
std::vector
al.push_back(a);
it could be that you haven't defined opeartor= correctly:
note 'other' is passed by constant reference.
class ClassXYZ {public: ClassXYZ& operator=(const ClassXYZ& other);};note 'other' is passed by constant reference.
this is definition of V3_s
struct V3_s //3D Vector
{
public:
float X,Y,Z;
void setZero() { X = Y = Z = 0.0f; };
void operator = (V3_s inVec)
{
X = inVec.X;
Y = inVec.Y;
Z = inVec.Z;
};
bool operator == (V3_s inVec)
{
if( inVec.X == X && inVec.Y == Y && inVec.Z == Z )
return true;
return false;
};
};
struct V3_s //3D Vector
{
public:
float X,Y,Z;
void setZero() { X = Y = Z = 0.0f; };
void operator = (V3_s inVec)
{
X = inVec.X;
Y = inVec.Y;
Z = inVec.Z;
};
bool operator == (V3_s inVec)
{
if( inVec.X == X && inVec.Y == Y && inVec.Z == Z )
return true;
return false;
};
};
And everything is clear now.
The reason was that you lack word const.
std::fill(class CShape *,class CShape *,const class CShape &)
needs const class CShape, to perform assignment, and it could not since one of it's members didn't have const assignment operator.
EDIT:
The order of compiling templated code is a mystery to me. Explanation:
One of the operations in operator=(CShape) is an assignment of vector. If the compiler tried to generate it before operator=(V3_s), it would have shout about not having operator=(const V3_s) and the bug would have been spotted instantly.
Unfortunately, it stopped earlier, realizing that there is no chance of generating operator=(const CShape). Reason given: unknown.
void operator = (V3_s inVec){ X = inVec.X; Y = inVec.Y; Z = inVec.Z;};// Should be changed to:void operator = (const V3_s inVec){ X = inVec.X; Y = inVec.Y; Z = inVec.Z;};// Or even better and standard compliant:V3_s& operator = (const V3_s inVec){ X = inVec.X; Y = inVec.Y; Z = inVec.Z; return *this;};The reason was that you lack word const.
std::fill(class CShape *,class CShape *,const class CShape &)
needs const class CShape, to perform assignment, and it could not since one of it's members didn't have const assignment operator.
EDIT:
The order of compiling templated code is a mystery to me. Explanation:
One of the operations in operator=(CShape) is an assignment of vector
Unfortunately, it stopped earlier, realizing that there is no chance of generating operator=(const CShape). Reason given: unknown.
Quote:
Original post by deffer
And everything is clear now.
*** Source Snippet Removed ***
The reason was that you lack word const.
std::fill(class CShape *,class CShape *,const class CShape &)
needs const class CShape, to perform assignment, and it could not since one of it's members didn't have const assignmet operator.
Those should be constant references.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement