function with argument lists as string. Is it possible?

I want to create a function with accepts strings as arguments, but I cant seem to make it happen. This is closest I've got.

1
2
3
4
5
6
7
8
9
10
11
12
  Deck::Deck( int num, ... ){
  va_list arguments;
  double sum = 0;

  va_start ( arguments, num );
  for ( int x = 0; x < num; x++ ){
        stringstream ss;
    ss <<  va_arg ( arguments, int );
  cout << ss.str();
  }
  va_end ( arguments );
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// http://ideone.com/7Zf7Bv
#include <string>
#include <vector>
#include <iostream>
#include <initializer_list>

struct Deck
{
    Deck(std::initializer_list<std::string> init_list) : _deck(init_list.begin(), init_list.end()) {}

    const std::vector<std::string>& get() const { return _deck; }
private:
    std::vector<std::string> _deck;
};

int main()
{
    Deck d({ "rock", "paper", "scissors" });

    for (auto card : d.get())
        std::cout << card << '\n';
}
Topic archived. No new replies allowed.