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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -