c++ - how to struct initializer and deque -
c++ - how to struct initializer and deque -
so have..
struct polynomial{ deque<long> coefs; long degree; polynomial(initializer_list<long> co_list); polynomial(deque<long> & co_list); polynomial(); string poly_to_string(); polynomial add(polynomial rhs); polynomial mult(polynomial rhs); polynomial mult(long factor); }
for theese methods have :
polynomial(initializer_list cfs ). initialize instance using initializer list of coefficients. -order highest powerfulness goes first, lowest lastly -coefs , grade updated.
polynomial(deque cfs). initialize instance using vector of coefficients. -order highest powerfulness goes first, lowest lastly -coefs , grade updated.
then methods add/multiple/factor polynomial, can do, not sure what
polynomial(initializer_list<long> co_list); polynomial(deque<long> & co_list);
are suppose / how start them..
also, how would start function homecoming polynomial.degree homecoming long value?
those 2 functions constructors type. tell compiler how set polynomial
object it's ready members called. they're understood this:
struct polynomial{ deque<long> coefs; long degree; polynomial(initializer_list<long> co_list); polynomial(deque<long> & co_list); }; polynomial::polynomial(initializer_list<long> co_list) { //at point, members created, have no values //so assign values members coefs.assign(co_list.begin(), co_list.end()); grade = co_list.size(); } int main() { polynomial mypoly = {3, 4, 5}; //creates polynomial variable initializer list //the compiler runs constructor function automatically //so it's members set, , can run other functions mypoly.do_thing(); }
however, shown above, polynomial
constructor constructs 2 members, , executes function assigns them values. can create improve constructing them straight intended values:
polynomial::polynomial(initializer_list<long> co_list) : coefs(co_list.begin(), co_list.end()), //constructed straight degree(co_list.size()) { //they have needed values, don't need more //to finalize construction }
c++
Comments
Post a Comment