C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: std::vector question

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Hamish
Guest





PostPosted: Thu Dec 30, 2004 4:57 am    Post subject: Re: std::vector question Reply with quote



Quote:
I havea program which on execution gives unpredictable behaviour (it
shouldn't). In trying to track down the problem, I'm wondering if there
is
a
difference between these two ways of filling a std::vector with data:

Method 1:

std::vector<int> v;
int k;

for(i=0;i<n;i++){
k = i + 3;
v.push_back(k);
}

Method 2:

std::vector
for(i=0;i<n;i++){
int k = i + 3;
v.push_back(k);
}


The only difference with these two methods is the scope of k but this
doesnīt affect the behavior in this case. Please post your real code which
gives you trouble.

I haven't been able to track down the problem yet. However, the only
difference between an older version which worked, adn this version is the
following data structures:

std::vector
class PolyTypeClass{
public:
PolyTypeClass();
virtual ~PolyTypeClass();

const PolyTypeClass& operator= (const PolyTypeClass& poly);
void Copy(PolyTypeClass * pCopy);

int ID;
std::vector<BasePolygonClass> Rot;
};

class BasePolygonClass{
public:
BasePolygonClass();
BasePolygonClass(int Size);
virtual ~BasePolygonClass();

const BasePolygonClass& operator= (const BasePolygonClass& poly);
void Copy(BasePolygonClass * pCopy);

std::vector<PointPropClass> Points;
double Area;
double Length;
double Height;
BOOL IsConvex;
double Angle;
BOOL XFlip;
BOOL YFlip;
};

class PointPropClass
{
public:
PointPropClass();
virtual ~PointPropClass();
const PointPropClass& operator= (const PointPropClass& poly);
void Copy(PointPropClass * pCopy);

BOOL TP;
double Angle;
int Num;
int CavNum;
int St;
int Fin;
int Type;
BOOL Neg;
BOOL IsGhosh;
double x;
double y;
};



Back to top
Chris Theis
Guest





PostPosted: Thu Dec 30, 2004 8:28 am    Post subject: Re: std::vector question Reply with quote




"Hamish" <h.dean (AT) xtra (DOT) co.nz> wrote

Quote:
I havea program which on execution gives unpredictable behaviour (it
shouldn't). In trying to track down the problem, I'm wondering if
there
is
a
difference between these two ways of filling a std::vector with data:

Method 1:

std::vector<int> v;
int k;

for(i=0;i<n;i++){
k = i + 3;
v.push_back(k);
}

Method 2:

std::vector
for(i=0;i<n;i++){
int k = i + 3;
v.push_back(k);
}


The only difference with these two methods is the scope of k but this
doesnīt affect the behavior in this case. Please post your real code
which
gives you trouble.

I haven't been able to track down the problem yet. However, the only
difference between an older version which worked, adn this version is the
following data structures:

std::vector
class PolyTypeClass{
public:
PolyTypeClass();
virtual ~PolyTypeClass();

const PolyTypeClass& operator= (const PolyTypeClass& poly);
void Copy(PolyTypeClass * pCopy);

int ID;
std::vector<BasePolygonClass> Rot;
};

class BasePolygonClass{
public:
BasePolygonClass();
BasePolygonClass(int Size);
virtual ~BasePolygonClass();

const BasePolygonClass& operator= (const BasePolygonClass& poly);
void Copy(BasePolygonClass * pCopy);

std::vector<PointPropClass> Points;
double Area;
double Length;
double Height;
BOOL IsConvex;
double Angle;
BOOL XFlip;
BOOL YFlip;
};

class PointPropClass
{
public:
PointPropClass();
virtual ~PointPropClass();
const PointPropClass& operator= (const PointPropClass& poly);
void Copy(PointPropClass * pCopy);

BOOL TP;
double Angle;
int Num;
int CavNum;
int St;
int Fin;
int Type;
BOOL Neg;
BOOL IsGhosh;
double x;
double y;
};


What strikes me (although in this case it should not pose a problem after a
quick glance at your code) is that you do supply a dtor and an assignment op
but not a copy ctor. If you really need a dtor & an assignment op itīs good
practice to supply a copy ctor too.

If you could please post the actual code of "Method 1" & "Method 2" which
works with your data structures and also the implementation of the Copy()
method would be interesting.

Cheers
Chris



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.