my program has a function to calculate a certain amount, for this I need to access the attributes of the objects in the vector:
Vector Declaration:
class trilateration {
public:
...
std::vector<tip> *potential;
...
};
then in the constructor it is initialized:
trilateration::trilateration()
{
...
potential = new std::vector<tip>();
...
}
the class is as follows:
class tip {
public:
double sum;
Point2d *pt;
tip();
tip(double x, double y);
virtual ~tip();
};
hint constructor:
tip::tip(double x, double y)
{
pt = new Point2d(x,y);
sum=0;
}
objects are added to the vector in some functions as follows:
potential->push_back(tip1);
then I want to access some objects in the vector:
void trilateration::get3points()
{
for(int i=0; i<potential->size(); ++i)
{
for(int j=0; j<potential->size(); ++j)
{
potential[i].sum=potential[i].sum+normalize(potential[i].pt,potential[j].pt);
}
}
}
when compiling im getting the following error:
error: ‘class std::vector<tip>’ has no member named ‘sum’
error: ‘class std::vector<tip>’ has no member named ‘pt’
How can I use these attributes from a vector?
EDIT:
after changing the potential to be a member of trilateration and pt to be a member of the tip, the program compiled, but when it occurs
potential.push_back(tip1);
throws:
*** glibc detected *** ./loktest: malloc(): memory corruption: 0x00792f10 ***