Thursday 15 July 2010

C++: Converting Array class to Class template (Scope issue) -


I am in the initial stage of trying to change an array class, which includes the overloading operator in a templated class. At the moment, I am trying to add the definition of the template to the class and every function. It should be quite simple, however, whenever I run the program, I get a scope error.

The compiler says that 'T' was not declared in this radius (I would comment on the error that happens). The error also occurs on other function definitions. I am using a templated class as a program and it implements the tasks I am trying to do (which is why I am confused). What should I do to resolve this?

Thank you.

  #include & lt; Iostream & gt; # Include & lt; Iomanip & gt; # Include & lt; Cstdlib & gt; # Include & lt; Stdexcept & gt; using namespace std; #ifndef ARRAY_H #define ARRAY_H template & lt; Typename T & gt; Class array {public: arrays (int = 10); Array (Constant Array & amp; nbsp;); ~ Array (); Int getSize () console; Constant Array and Operator = (Constant Ar & amp; amp;;); Bull Operator == (Const Ar and Co.); Bull Operator! = (Constant Array and Right) const {Return! (* It == true); } Int and operator [] (int); Int operator [] (int) const; Private: integer size; Int * ptr; }; #endif Template & lt; Typename t & gt; Array End Lieutenant; T & AG :: Array (Int. Sir Sysi) // Error: T was not declared in this scope ************************************************************ Throw ***** and invalid_gram ("Array Size Mayest Is More Than 0"); Ptr = new int [size]; For (Int i = 0; I   

Before each of your function definitions, you have written: < Previous> template & lt; Typename t & gt;

Your mean:

  template & lt; Typename T & gt;   

That is, it should match the template parameters of your square, which is the capital T .

No comments:

Post a Comment