Last active
June 29, 2016 06:18
-
-
Save ArchangelSDY/5889ac4dca76fc2bc30cf7615f5f6cd3 to your computer and use it in GitHub Desktop.
initializer_list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <initializer_list> | |
#include <string> | |
#include <list> | |
#include <iostream> | |
using namespace std; | |
class Book | |
{ | |
public: | |
string bookname; | |
double price; | |
string author; | |
Book(const string &b, double p, const string &a) : | |
bookname(b), | |
price(p), | |
author(a) {} | |
}; | |
class S | |
{ | |
public: | |
S(initializer_list<Book> _books) | |
{ | |
books.insert(books.end(), _books.begin(), _books.end()); | |
} | |
void append(initializer_list<Book> _books) | |
{ | |
books.insert(books.end(), _books.begin(), _books.end()); | |
} | |
list<Book> books; | |
}; | |
int main() | |
{ | |
S s = {{"aaa", 1, "bbb"}}; | |
cout << s.books.size() << endl; | |
cout << s.books.back().author << endl; | |
s.append({{"ccc", 2, "ddd"}, {"eee", 3, "fff"}}); | |
cout << s.books.size() << endl; | |
cout << s.books.back().author << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment