Pass std :: array as a reference parameter

I can pass my array directly, but I need to know how to pass it by reference. I am using the new std :: array with type Element. I tried several things, but they do not work. I am not sure how to pass this as a link. I got it mixed up and I can't figure it out.

How to pass std :: array as a reference parameter to avoid copying the whole array?

How my array is configured:

std::array<Element, 115> Elements =
{{
    /*int aNumber, float awNumber, period_number PERIOD, group_names GROUP_NAME, metal_status METALSTATUS,
    valence_shell Orbital,std::string eName, std::string eSybol);*/
    {},
    {1,     1.00794,        period::PERIOD_ONE,     group::HYDROGEN,        metal::NONMETAL,    shell::S_ORBITAL,   "Hydrogen",     "H"}
}};

AT

void sortByAtomicNumber(std::array<Element, 115> elements, int minimum, int maximum)
{
    int counter = 1;
    for(;minimum < (maximum+1); minimum++)
    {
        std::cout << counter << ".) " << elements[minimum].getElementName() << std::endl;
        counter++;
    }
}

Tried From: http://gauravpandey.com/wordpress/?p=602 // I have not yet studied the patterns ...

 template<size_t N>
void sortByAtomicNumber(std::array<int, N> const& arr, int maximum, int minimum) {
    int counter = 1;
    for(;minimum < (maximum+1); minimum++)
    {
        std::cout << counter << ".) " << arr[minimum].getElementName() << std::endl;
        counter++;
    }
}

Error above


error: passing 'const value_type {aka const Element}' as the argument to 'this' from std :: string → Element :: getElementName ()' discards qualifiers [-fpermissive]


+3
2

:

void sortByAtomicNumber(std::array<Element, 115> &elements, int minimum, int maximum)
{
    int counter = 1;
    for(;minimum < (maximum+1); minimum++)
    {
        std::cout << counter << ".) " << elements[minimum].getElementName() << std::endl;
        counter++;
    }
}
+1

:

  • sortByAtomicNumber, std::array<int, N> std::array<Element, N>.

  • const, const. , arr const, void getElementName(); Element be void getElementName() const;.

  • , const. template<size_t N> void sortByAtomicNumber(std::array<int, N> const& arr, int maximum, int minimum) { /* your code */ } template<size_t N> void sortByAtomicNumber(std::array<Element, N>& arr, int maximum, int minimum) { /* your code */ }, , @portforwardpodcast said.

. const const . , .

+1

All Articles