Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #struct
ADD COMMENT
Topic
Name
2+3 =