From: "Traveler" Newsgroups: comp.lang.c++,comp.os.msdos.djgpp Subject: Re: GENERAL DATA TYPE (Do you need one ?) Date: Wed, 21 Mar 2001 15:21:44 +0200 Organization: SAUNALAHDEN asiakas Lines: 94 Message-ID: <99a8ig$3ms$1@tron.sci.fi> References: <9988r4$k33$1 AT tron DOT sci DOT fi> <9989to$s25$1 AT nnrp DOT atgi DOT net> <998h4d$5o0$1 AT tron DOT sci DOT fi> <998hls$sj5$1 AT nnrp DOT atgi DOT net> NNTP-Posting-Host: mmmdccxix.hdyn.saunalahti.fi X-Trace: tron.sci.fi 985179537 3804 195.197.164.119 (21 Mar 2001 12:58:57 GMT) X-Complaints-To: newsmaster AT saunalahti DOT fi NNTP-Posting-Date: 21 Mar 2001 12:58:57 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > A doubly-linked list of anything? Why? It doesn't make any > sense to have everything as a potential member of the list. > > > > // The following would be possible... > > > > int x = f(); > > > > long y = f(); > > > > > > What would that do? > > It depends.... > > What would you like it to do ??? > > Precisely. When I need some functionality, I put it there. > And in most cases the way it is implemented and _named_ must > make some sense for those who read the code. > > > (I certainly know what the "Object& getNode(DWORD index)" will do !!! > :=)) > > I don't. What would it do? Is that a global function? Itīs a member function of the list which will return any object stored in the current index position inside the list. > the 'getNode' method of class List should return the type > of the List's element. Yes, if you want to it the standard way which can only return one and only one type.... " template class List { class Node { public: Node* prev; T data; Node* next; } *first; public: T& getNode(DWORD index)const; ... ... ... };" But as I stated above, I don't see > any sense of having a generic "list of anything". > I have... > > > > > > > // So would this... > > > > int x = 10; > > > > int y = 20; > > > > Object tmp; > > > > tmp = x; > > > > x = y; > > > > y = tmp; // Now, x has 20 & y has 10 > > > > > > Why can't 'tml' be 'int'? > > That was just an example.... > > Bad example, as it turns out. I addmit.... > > > Point is it works and it can handle ALL the basic data types > > Again, what for? The whole idea of type-specific programming is > to make object distinguishable not only by their name (address) > but by their type as well. I know, but there might be a need sometimes in the future where you need a generic type. When you do give me a call :) > > > > > You can also use it on those of your own work. > > But why? I will use the type I need, not a generic one. > > > > > The only catch is that A) you have to use inheritance & B) you have to > > define conversion function that returns some value from your object > > There is no need. A generic "replacement for everything" object > will be _unable_ to do anything -- it simply will not be able to > have _any_ functionality. Are you sure ??? :) Besides, we already have a type for > that. It's called "pointer to void". > Yeah, if you want to do those type conversions by hand... void* p; p = (int*)new int[500];