Answers for "push_back struct c++"

C++
1

push_back struct c++

struct point { // Our struct
    int x;
    int y;
};

// How you would normally do it
point mypoint = {0, 1};
a.push_back(mypoint);

// OR define a constructor
point make_point(int x, int y) {
    point mypoint = {x, y};
    return mypoint;
}

a.push_back(make_point(0, 1));
Posted by: Guest on February-17-2022

Browse Popular Code Answers by Language