|
发表于 2020-9-20 00:00:35
|
显示全部楼层
本楼为最佳答案
是要实现++操作符的重载吗?
- #include <iostream>
- //template <typename T> Test<T> operator++(Test<T>& t);
- template <typename T>
- class Test {
- T a;
- T b;
- public:
- Test(T a, T b)
- {
- this->a = a;
- this->b = b;
- }
- Test<T> & operator ++()
- {
- a++;
- b++;
- return * this;
- }
- void Print()const
- {
- std::cout << a << " , " << b;
- }
-
- // template <typename T>
- // friend Test<T> operator++(Test<T>& t);
- };
- int main()
- {
- Test<int> test(0, 0);
- (++test).Print();
- return 0;
- }
- //template <typename T> Test<T> operator++(Test<T>& t)
- //{
- // return Test<T>(++t.a, ++t.b);
- //}
复制代码 |
|