Mail Archives: djgpp/2001/03/21/08:01:40
> 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 T>
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];
- Raw text -