Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- //pierwsze
- template <typename T, typename K>
- auto add1(T a, K b){
- return a+b;
- }
- //drugie
- template <typename T, typename K, typename F>
- auto add2(T a, K b, F f ){
- return f(a,b);
- }
- //trzecie
- template<class T, int N, T k=0>
- class Wektor
- {
- private:
- T tab[N];
- public:
- T & operator[](int j) {return tab[j];}
- const T & operator[](int j) const {return tab[j];}
- Wektor()
- {
- for(int i=0;i<N;i++)
- {
- tab[i]=k;
- cout<< tab[i]<<" ";
- }
- }
- };
- int a1=5, a2=4;
- string b1 = "doo", b2 = "sth";
- float c1 = 3.14f, c2 = 9.2f;
- int main()
- {
- cout << "Pierwsze zadanie"<< endl;
- cout << add1(a1, c1) << endl;
- cout << add1(b1,b2) << endl;
- cout << add1(c1,c2) << endl;
- //cout << addsth<string,string>("dd","aaad") << endl;
- cout << "\nDrugie zadanie" << endl;
- auto fun= [](auto &a, auto&b){
- return a+b;
- };
- cout << add2(a1, c2, fun)<< endl;
- cout << add2(b2, b1, fun)<< endl;
- cout << "\n Trzecie zadanie"<< endl;
- Wektor<int,3,4> wekt;
- cout <<'\n';
- Wektor<int,5> r;
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement