开发者

question about templates [closed]

开发者 https://www.devze.com 2023-01-08 07:35 出处:网络
开发者_JAVA技巧 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
开发者_JAVA技巧 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

i have following code

#include <iostream>
#include <utility>
using namespace std;
namespace rel_ops{
    template<class t>bool operator!=(const t& x, const t& y){ return !(x==y);}
    template <class t>bool operator>(const t& x,const t& y){ return y<x;}
    template <class t>bool operator <=(const t& x,const t& y){ return !(y<x);}
    template  <class t> bool operator>=(const t& x,t& y) { return ! (x<y);}
    }
int main(){
    int x,y;

    cin>>x>>y;


     return 0;
}

i have question how implement it in main function? how implements its operators in main function


Here is an explanation and a nice example:

http://www.cplusplus.com/reference/std/utility/rel_ops/


You just need to add:

using namespace rel_ops;

Note that rel_ops is already defined in std. You do not need to redefine this namespace and its contents in your code. To use the definition already present in std, you use just:

#include <utility>
using namespace std::rel_ops;
0

精彩评论

暂无评论...
验证码 换一张
取 消