Hello.. I need a little help getting pointed in the right direction on an exercise that I am working on. I am attempting to create a templated Array class. In the process of this, I need to overload the arithmetic operators (+ and -), the i/o streams, subscript operators, and assignment operators.
Right now, I am just trying to focus on one part of that at a time. I want to try and get the ostream << operator running right, but I can't quite seem to get it.
Below is my code;
I am getting the following errors when compiling:Code:#include <iostream> using namespace std; template <class Type, MAX_ELEMENTS> class Array { protected: Type *pTypeArray; public: Array() {pTypeArray=new Type[ MAX_ELEMENTS ];} ~Array() {delete[] pTypeArray;} friend ostream& operator <<(ostream&, const Array &); }; template <class Type> ostream &operator<<(ostream &output, const Array<Type, MAX_ELEMENTS> &a){ // I know something else goes here, but not sure of the exact syntax return output; } // Main function used to test Array class implementation // Attempting to create an Array of 10 ints, then loop through // each and assign them with values of 0 through 9, then // have the output be printed out. int main() { Array<int,10> test; int i; for (i=0; i <10; i++) { test[i]=i; cout << test[i]; } return 0; }
I am hoping that someone can point me/lead me in the right direction. I by no means want someone to simply give me the answer.. I just need a gentle nudge.Code:C:\Program Files\Microsoft Visual Studio\MyProjects\CS468_MiniProject1\MiniProject1.cpp(5) : error C2061: syntax error : identifier 'MAX_ELEMENTS' C:\Program Files\Microsoft Visual Studio\MyProjects\CS468_MiniProject1\MiniProject1.cpp(21) : error C2065: 'MAX_ELEMENTS' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\CS468_MiniProject1\MiniProject1.cpp(30) : error C2977: 'Array' : too many template arguments C:\Program Files\Microsoft Visual Studio\MyProjects\CS468_MiniProject1\MiniProject1.cpp(18) : see declaration of 'Array' C:\Program Files\Microsoft Visual Studio\MyProjects\CS468_MiniProject1\MiniProject1.cpp(30) : error C2079: 'test' uses undefined class 'Array<int>' C:\Program Files\Microsoft Visual Studio\MyProjects\CS468_MiniProject1\MiniProject1.cpp(35) : error C2109: subscript requires array or pointer type C:\Program Files\Microsoft Visual Studio\MyProjects\CS468_MiniProject1\MiniProject1.cpp(35) : error C2106: '=' : left operand must be l-value C:\Program Files\Microsoft Visual Studio\MyProjects\CS468_MiniProject1\MiniProject1.cpp(36) : error C2109: subscript requires array or pointer type Error executing cl.exe.
Thanks in advance for your help!



LinkBack URL
About LinkBacks



