c++ - template warnings and error help, (gcc) -


I am working on a container class template (int, balls, string etc.), and I'm stuck with it This error

  cont.h: 56: Error: 'Expected Starter before initiating' token for this section  

  template & lt; Typename T & gt; Constant & amp; Container & lt; T & gt; :: operator = (const container & lt; T & gt; rightCont) { 

What have I done wrong?

It's also not sure whether this warning message means. Note: Friend declaration `Bull Operator == (Constructor & lt; T & gt; and Constant Container & lt; T & gt; & amp; Template function cont.h: 13: Warning: (If this is not for your purpose, make sure that the function template has already been declared and add & lt; & gt; after the function name) -no-non -Template-Friend In this situation

disables this warning

  template & lt; Typename T & gt; Class Container {Buddy Operator == (Constant & lt; T & gt; RA, Constrenner & lt; T & gt; & amp; LHS); Public:  

In the first case, you have reverted the previous things when you specify the return type , You must include the template parameter list in the template identifier ( container & gt; ), but when you specify the parameter type, you do not need to do this (Just container is enough)

  template & lt; Typename T & gt; Const container & lt; T & gt; & Amp; Container & lt; T & gt; :: operator = (const container & rightCont) {...  

You have done it another way for any other reason.

The second case, when you declare operator == as a friend, it only warns you that in this case operator == You are talking about a normal function, it can not be a specialization of a template. To wit. Class container & lt; Int & gt; function

  for bool operator == (const container & lt; int & gt; and rhs, const container & lt; int & gt; & amp; lhs) / ...}  

will be a friend but specialization of the function template

  template & lt; Square U & gt; Bool operator == (const container & lt; u & gt; and rhs, const container & lt; u & gt; and amp; lhs)  

for u == int not container & lt; Int & gt; will be your friend. If this is your intention, then you are fine.

If you want to befriend specific specialization of the template above, then you have to say

  template & lt; Typename T & gt; Class Container {Buddyzer Operator == & lt; T & gt; (Constant & lt; T & gt; R & R, Constraint & lt; T & gt; & amp; LHS); ...  

If you want to befriend all specialization of the template above, then you have to say

  Template & Lt; Typename T & gt; Square container {template & lt; Class U & gt; Buddy Bull Operator == (Constant & lt; U & gt; amp; rhs, const container & lt; U & gt; & amp; LHS); ...  

Comments