Type1_object + Type2_object
template <class T>MyVector {/*...*/class iterator:public: template <class C> friend const iterator& operator+(const iterator& iter, size_type step);};};template <class T>const typename AtdVector<T>::iterator& operator+(const typename AtdVector<T>::iterator& iter, typename AtdVector<T>::size_type step) { /*...*/}
templateFunction<Type>(...);
template <class C> friend const iterator& operator+(const iterator& iter, size_type step);
typename AtdVector<T>::size_type step
template <class T>MyVector { // <---- ошибка синтаксиса: непонятный символ: MyVector/*...*/class iterator: // <---- ошибка синтаксиса: похоже на объявление класса, за которым должно последовать наследование.public: template <class C> friend const iterator& operator+(const iterator& iter, size_type step);};};template <class T>const typename AtdVector<T>::iterator& operator+(const typename AtdVector<T>::iterator& iter, <---- ошибка синтаксиса: неопознанный символ AtdVector typename AtdVector<T>::size_type step) { /*...*/}
templFunc<int>(...)
typedef unsigned int size_type;
C++ (Qt)#include <iostream> template <class T>class Iterator; template<class T>const Iterator<T> operator+(const Iterator<T>&, typename Iterator<T>::size_type); template <class T>class Iterator{public: typedef size_t size_type; Iterator() {} explicit Iterator(const Iterator &, size_type) {} friend const Iterator operator+<>(const Iterator &, size_type); private: }; template <class T>const Iterator<T> operator+(const Iterator<T> & it, typename Iterator<T>::size_type n) { return Iterator<T>(it, n);} int main(){ Iterator<int> it; it + 2; return 0;}
template <class T>class TplClass;template <class T>const TplClass<T>& operator+(const TplClass<T>& lhs, const TplClass<T>& rhs);template <class T>class TplClass {public:/*...*/friend const TplClass& operator+(const TplClass<T>& lhs, const TplClass<T>& rhs);/*...*/}
#ifndef TPLNUMBER_H#define TPLNUMBER_Htemplate <class T>class TplNumber;template <class T>const TplNumber<T>& operator+(const TplNumber<T>& lhs, const TplNumber<T>& rhs);template <class T>class TplNumber {public: TplNumber(T val) : _val(val) {} friend const TplNumber& operator+(const TplNumber& lhs, const TplNumber& rhs);private: T _val;};///////////////////////////////////////////////////////////////////////////////template <class T>const TplNumber<T>& operator+(const TplNumber<T>& lhs, const TplNumber<T>& rhs) { return TplNumber<T>(lhs._val + rhs._val);}#endif // TPLNUMBER_H
/* main.cpp */#include <iostream>#include "tplnumber.h"using namespace std;int main(){ cout << "Hello World!" << endl; TplNumber<int> num1(4); TplNumber<int> num2(3); TplNumber<int> sum = num1 + num2; return 0;}
C++ (Qt)template <class T>class TplNumber; template <class T>const TplNumber<T> operator+(const TplNumber<T>&, const TplNumber<T>&); template <class T>class TplNumber {public: TplNumber(T val) : _val(val) {} friend const TplNumber operator+<>(const TplNumber &, const TplNumber &); private: T _val;}; template <class T>const TplNumber<T> operator+(const TplNumber<T>& lhs, const TplNumber<T>& rhs) { return TplNumber<T>(lhs._val + rhs._val);} int main(){ TplNumber<int> num1(4); TplNumber<int> num2(3); TplNumber<int> sum = num1 + num2; return 0;}
friend const TplNumber& operator+<>(const TplNumber& lhs, const TplNumber& rhs);
template <class T>class TplNumber {// ...friend const TplNumber& operator+<>(const TplNumber& lhs, const TplNumber& rhs) { return TplNumber(lhs.value() + rhs.value());}// ...};