Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Generics

Name: Anonymous 2012-05-30 15:18

I didn't know C++ generics were this powerful


#include <iostream>
#include <array>

template<typename T, std::size_t N>
void print_members(const std::array<T, N>& arr)
{
    for (auto it = arr.cbegin(); it != arr.cend(); ++it) {
        std::cout << *it << std::endl;
    }
}

int main(int argc, char** argv)
{
    std::array<int, 5> numbers = {{1,2,3,4,5}};
    std::array<char, 5> letters = {{'A','B','C','D','E'}};

    print_members(numbers);
    print_members(letters);

    return 0;
}

Name: Anonymous 2012-05-31 0:42

>>7
Just like C.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List