Feb 10, 2016 at 4:24pm UTC
Trying to write a simple program that can successfully pass an std::array (card_deck) to a function (print_array). I don't know the parameters I should pass:
print_array(??)
{};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include<iostream>
#include <array>
using namespace std;
print_array( ?card_deck)
{
do stuff
}
int main()
{
int ctr(0);
array<int , 52> card_deck;
int ctr_1(0), loop(0);
while (loop++ <4)
{ ctr_1=1;
while (ctr_1++ <13)
{ //cout<<"loop val:"<<ctr_1;
card_deck[ctr_1] = ctr_1;
cout<<card_deck[ctr_1]<<" " ;
}
}
return 0;
}
How do I pass the std::array?
Last edited on Feb 10, 2016 at 4:30pm UTC
Feb 10, 2016 at 4:37pm UTC
void print_array( std::array<int ,52>& card_deck)
Feb 10, 2016 at 4:48pm UTC
If you want you can give the deck type an alternative name that is easier to remember.
typedef array<int , 52> CardDeck;
Then you can use that name instead of array<int, 52> everywhere.
1 2 3 4 5 6 7 8 9 10
void print_deck(const CardDeck& card_deck)
{
// do stuff
}
int main()
{
CardDeck card_deck;
print_deck(card_deck);
}
Last edited on Feb 10, 2016 at 4:54pm UTC
Feb 10, 2016 at 6:19pm UTC
Thx, all straightened out!