Advertisement
Guest User

Untitled

a guest
Jun 20th, 2010
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4. template<class S>
  5. S make_struct() {
  6.     S s = {};
  7.     return s;
  8. }
  9.  
  10. template<class S, class T1>
  11. S make_struct(T1 t1) {
  12.     S s = { t1 };
  13.     return s;
  14. }
  15.  
  16. template<class S, class T1, class T2>
  17. S make_struct(T1 t1, T2 t2) {
  18.     S s = { t1, t2 };
  19.     return s;
  20. }
  21.  
  22. // ... etc.
  23.  
  24. struct X { int a, b; };
  25.  
  26. int main() {
  27.     X x = make_struct<X>(1, 2);
  28.     std::cout << x.a << ", " << x.b << "\n";
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement