I have following class:
template <size_t size>
class Araye{
public:
Araye(int input[]){
for (int i=0;i<size;i++)
araye[i]=input[i];
}
int araye[size];
};
How should I write a cast-to-reference-to-array operator for this class so that following works:
int adad[3]={1,2,3};
Araye<3> araye(adad);
int (&reference)[3]=araye;
Or with
identity(thanks Johannes):With that your example works, but i’d prefer the following declaration instead:
There usually should be no need for this though as the subscripting operator should cover most needs:
Note that if you are ok with limiting your class to being an aggregate, you could shorten your sample to the following instead: