Jump to content
  • Advertisement
Sign in to follow this  
Komillos

STL problem

This topic is 4869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's what i got ClassXYZ a; std::vector<ClassXYZ> 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

Share this post


Link to post
Share on other sites
Advertisement
Template error messages tend to be unhelpful.

Are you defining a custom copy constructor/assignment operator?

If so, are either of them protected or private?


If not, could you post the actual code that's causing this problem?

Share this post


Link to post
Share on other sites
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<V3_s> 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<V3_s> 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<CShape> al;
al.push_back(a);

Share this post


Link to post
Share on other sites
it could be that you haven't defined opeartor= correctly:


class ClassXYZ {
public:
ClassXYZ& operator=(const ClassXYZ& other);
};


note 'other' is passed by constant reference.

Share this post


Link to post
Share on other sites
I just copy-pasted your code and it compiled...

I only added:
typedef int V3_s;
and set ctors to:
CShape() {};
~CShape() {};

since I don't know the definition of V3_s, and as you said, ctors don't do anything special..

So...?

Share this post


Link to post
Share on other sites
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;
};
};

Share this post


Link to post
Share on other sites
And everything is clear now.


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<V3_s>. 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Thanks alot , now it works , a more precise explanation of why the arguement should be declared as const?

Thanks alot , again

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!