c++ - What operator to overload if i want to use " a = {x, y};" -
i'm making own class , i'd able initilize title.
a = {x, y}; i haven't been able find point me how that.
assuming want able assign in way (not initialize), need overload operator=, argument types depend on list within braces represents.
if, example, going passing pair of values, can have operator= overload takes std::pair:
a& operator=(std::pair<int, int>); this callable so:
a a; = {5, 3}; if want able pass arbitrary length list, have argument type std::initializer_list:
a& operator=(std::initializer_list<int>); now of following fine:
a = {}; = {1, 2}; = {5, 3, 5, 2, 3};
Comments
Post a Comment