c++ list insert function problem

struct Vector3f
{
public : double x,y,z;
};

std::list<Vector3f> const *Points = new std::list<Vector3f>();

this is my implementation of the variables and types ...
and i wanted to insert a new variable but I cant how the syntax will be?
can anybody help me?


Vector3f *P = new Vector3f() ;
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
onMouse = 1;
Points->insert(0,P*); ??????
i wanted to insert a new variable ...
well, you can't because you have just declared a const list, perhaps you wanted to declare a const pointer to the list? In that case:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <list>

struct threeD//don't use vector, it means something else in C++
{
    double m_x;
    double m_y;
    double m_z;
    threeD (const double& x, const double& y, const double& z)
    : m_x(x), m_y(y), m_z(z) {}
};
std::ostream& operator << (std::ostream& os, const threeD& t)
{
    os << t.m_x << " " << t.m_y << " " << t.m_z << '\n';
    return os;
}
int main()
{
    std::list<threeD> * const Points = new std::list<threeD>();
    threeD first3D(0,0,0);
    (*Points).push_back(first3D);
    threeD second3D(1,1,1);
    (*Points).insert((*Points).begin(), second3D);

    for (auto& elem : (*Points))
    {
        std::cout << elem ;
    }
    delete Points
}

Output
1
2
1 1 1
0 0 0


Last edited on
Topic archived. No new replies allowed.