Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5.  
  6. template <typename T, std::size_t X>
  7. class Wektor{
  8.  
  9. T z[X];
  10.  
  11. public:
  12. Wektor(){
  13. for(int i = 0; i < X; i++){
  14. z[i] = 0; }
  15. }
  16.  
  17. typedef T value_type;
  18. T& operator[](std::size_t y) {
  19. return z[y];
  20. }
  21.  
  22. };
  23.  
  24. template <typename w, typename q>
  25.  
  26. typename w::value_type operator*(w x, q y){
  27. typename w::value_type sum =0;
  28. for (int i = 0; i < 3 ;i++){
  29. sum = sum + x[i]*y[i];
  30. }
  31. return sum;
  32. }
  33.  
  34. int main() {
  35. Wektor<int, 3> wek;
  36. for ( int i = 0; i < 3; i++){
  37. std::cout << wek[i] << "\n";
  38. }
  39. Wektor<int,3> wek2;
  40. std::cout <<"\n" << wek*wek2;
  41.  
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement