| | |
Custom Array Class
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 67
Reputation:
Solved Threads: 1
I'm trying to create an template of an array class that encapsulates an array of a given type with several methods that are useful but nonstandard to regular c++ arrays. I have created a link struct to contain elements of the array and pointers to both the next and previous elements, and I am trying to overload the << operator to allow the value of a link to be printed easily simply by writing "cout << link_var" but I am having problems. Here is my code Also, a little side not, I'm not sure if the type() method is the proper return type, code, etc. I would appreciate any help that can be offered, thank you.
c++ Syntax (Toggle Plain Text)
#if !defined _LINK_ #define _LINK_ #if !defined _IOSTREAM_ #include _IOSTREAM_ #endif typedef unsigned short int size_l; template <typename T> class list; template <typename T> class link { typedef link<T>* link_p; T value; link_p next, previous; public: link() : value(NULL), next(NULL), previous(NULL) {} link( T _value, link_p _next= NULL, link_p _previous= NULL ) : value(_value), next(_next), previous(_previous) {} T rvalue() { return this->value; } link_p rnext() { return this->next; } link_p rprevious() { return this->previous; } const char* type() { return typeid(T).name(); }; friend class list<T>; template <typename CharT> friend std::basic_ostream<CharT> &operator<< ( std::basic_ostream<CharT> &out, const link &_link ) { out << _link.rvalue(); return out; } }; #endif /* _LINK_ */
•
•
Join Date: Feb 2008
Posts: 67
Reputation:
Solved Threads: 1
I'm sorry to keep throwing on questions, but I found one more question I have, is there a way to create a standard for operator function? For example, if I want something like this for operator declarations within a class to be able to work with all arithmetic operators (+, -, * and /)
cpp Syntax (Toggle Plain Text)
T operator{operator type here}( T _value ) { return ( this->value {operator type here} _value ); }
Last edited by c++noobie; Dec 14th, 2008 at 6:06 pm.
![]() |
Similar Threads
- An array of class objects question (C++)
- Client side code for a Web Method Returning a complex Custom data type. (RSS, Web Services and SOAP)
- Sorting Array (VB.NET)
- if statement involving array of a class (C2451) (C++)
- Programming VBA Dynamic Arry of Custom Class Problem (Visual Basic 4 / 5 / 6)
- Pass a 2D-array with AJAX (JavaScript / DHTML / AJAX)
- Custom Class - File I/O (C++)
- Irrational number data type (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: Integer partition: code works - any suggestion to improve it?
- Next Thread: Adding Arrays to my game
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





