Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

? Help With Simple Linked List Class Template
Hi,

I need to create a simple, custom linked-list type class.  I need it to be a
class template so that the items in the list can be any type.  Unfortunately
I have not been able to find any useful class/function template tutorials on
the Internet.  They are either to complex or too different.

Here's the basic requirements/outline:

*****************************
Node class {
**pointer to payload**;
**pointer to next node**;

int     intvar;
CString strvar;


Get/Set functions for each member variable();
}


List class {
**point to head of list**

int     someintvar;
CString somestrvar;

Get/Set functions for each member variable();
}
*****************************

I think that's about it.  I can handle this if I make the payload a specific
type but I need it to be like vector/CList/CArray etc.


Can anyone help me out with this?

Thank you very much.


--
Alec S.
alec <@> synetech <.> cjb <.> net



Report this thread to moderator Post Follow-up to this message
Old Post
Alec S.
03-23-05 02:01 AM


Re: ? Help With Simple Linked List Class Template
Alec S. wrote:
> I need to create a simple, custom linked-list type class.  I need it to be
 a
> class template so that the items in the list can be any type.  Unfortunate
ly
> I have not been able to find any useful class/function template tutorials 
on
> the Internet.  They are either to complex or too different.

Why are you looking for them on the Internet?  Don't you have books?
Which one are you using to learn the language?

> Here's the basic requirements/outline:
>
> *****************************
> Node class {

I now understand what you mean by "to complex"...

Report this thread to moderator Post Follow-up to this message
Old Post
Victor Bazarov
03-23-05 02:01 AM


Re: ? Help With Simple Linked List Class Template
I always like your replies:
Thats the correct reply.

"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:elp6icyLFHA.3832@TK2MSFTNGP12.phx.gbl...
> Alec S. wrote: 
>
> Why are you looking for them on the Internet?  Don't you have books?
> Which one are you using to learn the language?
> 
>
> I now understand what you mean by "to complex"...



Report this thread to moderator Post Follow-up to this message
Old Post
Tom Alter
03-23-05 02:01 AM


Re: ? Help With Simple Linked List Class Template
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:elp6icyLFHA.3832@TK2MSFTNGP12.phx.gbl...
> Why are you looking for them on the Internet?

I thought that's what the Internet is for.  Then again I suppose you only
use it for porn and piracy.


> Don't you have books?

No I don't have <very expensive> books.


> Which one are you using to learn the language?

None; I'm not learning the language, I already learned it many years ago
from "Teach Yourself C in 21 Days"-which I finished in much less.  I'm
trying to learn a feature that I have never used before.


Thanks for the "useful" reply.



It seems there are people here who don't understand the point to newsgroups.

Is there anyone here who has a desire to actually help rather than cut
everyone down?  I hope so.


--
Alec S.
news <.> alec <@> synetech <.> cjb <.> net



Report this thread to moderator Post Follow-up to this message
Old Post
Alec S.
03-23-05 09:01 AM


Re: ? Help With Simple Linked List Class Template
"Alec S." <a@a.com> wrote...
> "Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
> news:elp6icyLFHA.3832@TK2MSFTNGP12.phx.gbl... 
>
> I thought that's what the Internet is for.  Then again I suppose you only
> use it for porn and piracy.

No, actually, I don't use it for either of those purposes.  Internet is
a large place, but as a learning tool it is the least suitable out of all
means available to an average person.
 
>
> No I don't have <very expensive> books.

What books *do* you have?  Never mind.  I'll save you the embarrasment of
having to answer.  Take my advice: find a good book.  It doesn't have to
be expensive to serve its purpose.  "Accelerated C++" costs only CDN$ 44.09
and "SAMS Teach Yourself C++ in 21 Days" is only CDN$ 34.99 (on Amazon.ca).
More books are reviewed on www.accu.org and can be had used, undoubtedly.
 
>
> None; I'm not learning the language, I already learned it many years ago
> from "Teach Yourself C in 21 Days"-which I finished in much less.  I'm
> trying to learn a feature that I have never used before.

C does not have "Class Template" feature.  You seem a bit .  Are
you sure you learned C++ from a "Teach Yourself C" book?  Perhaps it was
just too many years ago and you need to spend a day to refresh your memory
a tiny bit.  Or perhaps you have no idea that C and C++ are not the same
language...  Either way, you're in dire need of a systematic study, AFAICS.

> It seems there are people here who don't understand the point to
> newsgroups.

Hmm...  Definitely.

V



Report this thread to moderator Post Follow-up to this message
Old Post
Victor Bazarov
03-23-05 09:01 AM


Re: ? Help With Simple Linked List Class Template
Hey, what do you know?  The block-newsgroup-messages-from-person feature
works!  :D

Anyway, now that I no longer have to waste time with a troll.  I'll add
that yes, I do know C and I do know C++ and MFC, and a about a dozen other
programming languages.  So I may not know every single little nook and
cranny of the languages, so what?  Is there anyone who does?  I know more
than enough to get by, to have written dozens, even hundreds of
tools/utilities.  I have never needed templates before so I never bothered
with them since I have too little time as it is.  I simplified the example
because 1) a lot of the details will be proprietary and 2) I wanted to weed
out the extraneous stuff that were not relevant to templates.


So, if there is anyone who actually knows class templates—it is safe to
assume little Vickie does not—and can help, then I thank you in advance.


--
news <.> alec <@> synetech <.> cjb <.> net



Report this thread to moderator Post Follow-up to this message
Old Post
Alec S.
03-23-05 09:01 AM


Re: ? Help With Simple Linked List Class Template
Hey, what do you know?  The block-newsgroup-messages-from-person feature
works!  :D


The example is simplified because 1) a lot of the details will be
proprietary and 2) I wanted to weed out the extraneous stuff that were not
relevant to templates, ie the stuff that I can add later.

I should also add that I read in a couple of places that the whole thing
should be in a single source file.  Do I have to put it in an HPP file then
or can I use separate h/cpp files?  Plus, I have found very little
information on constructors for template classes.  For example in the
implementation these fail to compile (error C2955: 'Node' : use of class
template requires template argument list):

///////////////////////////////////////
//h:
template <class T> class Node {
public:
Node(void);
~Node(void);
}

//cpp:
Node::Node(void) {
}

~Node::Node(void) {
}
///////////////////////////////////////

I've tried putting in the <T> on the constructor/destructor but then I get a
"'T' undeclared identifier" in the implementation.


So, if there is anyone who knows class templates and can help, then I thank
you in advance.


--
news <.> alec <@> synetech <.> cjb <.> net



Report this thread to moderator Post Follow-up to this message
Old Post
Alec S.
03-23-05 09:01 AM


Re: ? Help With Simple Linked List Class Template
template <class T> class Node {
public:
Node(void);
~Node(void);
}

//NOT cpp, but in .h:
template <class T>
Node<T>::Node(void) {
}

template <class T>
Node<T>::~Node(void)
{
}

These can be defined in the class definition, too; in that case they become
inlined.

"Alec S." <a@a.com> wrote in message
news:uUPlQq2LFHA.3392@TK2MSFTNGP10.phx.gbl...
> Hey, what do you know?  The block-newsgroup-messages-from-person feature
> works!  :D
>
>
> The example is simplified because 1) a lot of the details will be
> proprietary and 2) I wanted to weed out the extraneous stuff that were not
> relevant to templates, ie the stuff that I can add later.
>
> I should also add that I read in a couple of places that the whole thing
> should be in a single source file.  Do I have to put it in an HPP file
> then
> or can I use separate h/cpp files?  Plus, I have found very little
> information on constructors for template classes.  For example in the
> implementation these fail to compile (error C2955: 'Node' : use of class
> template requires template argument list):
>
> ///////////////////////////////////////
> //h:
> template <class T> class Node {
> public:
> Node(void);
> ~Node(void);
> }
>
> //cpp:
> Node::Node(void) {
> }
>
> ~Node::Node(void) {
> }
> ///////////////////////////////////////
>
> I've tried putting in the <T> on the constructor/destructor but then I get
> a
> "'T' undeclared identifier" in the implementation.
>
>
> So, if there is anyone who knows class templates and can help, then I
> thank
> you in advance.
>
>
> --
> news <.> alec <@> synetech <.> cjb <.> net
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Alexander Grigoriev
03-23-05 09:01 AM


Re: ? Help With Simple Linked List Class Template
why don't you just use std::list, or inherite anyway from std::list??

> Hi,
>
> I need to create a simple, custom linked-list type class.  I need it to be
a
> class template so that the items in the list can be any type.
Unfortunately
> I have not been able to find any useful class/function template tutorials
on
> the Internet.  They are either to complex or too different.
>
> Here's the basic requirements/outline:
>
> *****************************
> Node class {
>     **pointer to payload**;
>     **pointer to next node**;
>
>     int     intvar;
>     CString strvar;
>
>
>     Get/Set functions for each member variable();
> }
>
>
> List class {
>     **point to head of list**
>
>     int     someintvar;
>     CString somestrvar;
>
>     Get/Set functions for each member variable();
> }
> *****************************
>
> I think that's about it.  I can handle this if I make the payload a
specific
> type but I need it to be like vector/CList/CArray etc.
>
>
> Can anyone help me out with this?
>
> Thank you very much.
>
>
> --
> Alec S.
> alec <@> synetech <.> cjb <.> net
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
ben
03-23-05 02:00 PM


Re: ? Help With Simple Linked List Class Template
Thanks for the tips Alexander and ben but I actually found the perfect
answer somewhere else.


--
news <.> alec <@> synetech <.> cjb <.> net


"ben" <benhongh@hotmail.com> wrote in message
news:elP8Zc5LFHA.2736@TK2MSFTNGP09.phx.gbl...
> why don't you just use std::list, or inherite anyway from std::list??


"Alexander Grigoriev" <alegr@earthlink.net> wrote in message
news:OgAx5v2LFHA.1156@TK2MSFTNGP09.phx.gbl...
> template <class T> class Node {
> public:
>  Node(void);
>  ~Node(void);
> }
>
> //NOT cpp, but in .h:
> template <class T>
> Node<T>::Node(void) {
> }
>
> template <class T>
> Node<T>::~Node(void)
> {
> }
>
> These can be defined in the class definition, too; in that case they
become inlined.



Report this thread to moderator Post Follow-up to this message
Old Post
Alec S.
03-24-05 02:00 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

VC Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 01:14 PM.

 

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.