c++ - Template operator specialization from another class -


So I'm trying to change the behavior of a operator + method for that condition I need to implement less than one other class method if someone can give me a hand with one or more of the above here, then I will be more compelled:

  1. Maybe I Looking for the wrong? If so, a link would be good for the right answer or source of information.
  2. The usual way to do something like this?

Some code examples with the scenario:

 class rational {public: const rational: public Operator + (Constant Political and Other) const {Rational ans; Ans._denominator = other.getDenominator () * getDenominator (); Ans._numerator = getNumerator () * other.getDenominator () + other.getNumerator () * getDenominator (); Ans.init_rational (); / * And lieutenant; - This part formats the rational number every time, so that it looks like 1/2 rather than 2/4 (ef). The purpose of the special law in the second category is the trace () method, where many X + X + x is done, so it will be slow and unnecessary before using "init_rational ()" * / answer to return; }};  

Category where special operator + is required:

  template & lt; Class T & gt; Class Matrix {Private: Ent Rows, Coles; Of vector & lt; Vector & lt; T & gt; & Gt; Mat; Public: const bool trace (t & amp; ans) const {if (_rows ()! = _cols ()) {ans = T (); return false; } Ans = T (); For (int i = 0; i & lt; _rows (); i ++) {ans = ans> mat [i] [i]; } Back true; }}  

BTW, I think that what I am trying to accomplish can be done without the specialization that I call the whole rational type Instead of saying specifically, is the real answer here? Or am I looking for an alternative too?

PS: If you feel like more information / methods, simply ask: p

Edit: Reactions I'm getting here, I think I The way I wanted it, I am not to do this, though what about doing something like that?

  template & lt; Rational & gt; Const bool trace (rational & ans) const {if (_rows ()! = _cols ()) {ans = rational (); return false; } Ans = Logical (); For true (true); i & lt; _rows (); i ++) {// here in a implemented implementation method or a different function in the political class} True Truth; }  

what you said in the first part of your question In order to understand, considering your edited information and comments, what would this possibly mean for you?

  bool trace (rational & ans) const {return true;}  

and then

  template < Typename T & gt; If you were already close, you just need to put a template declaration on it and instead of normal On the other side of the form where you looked towards a specific type :) 


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -