Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageAlec 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"...
Post Follow-up to this messageI 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"...
Post Follow-up to this message"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
Post Follow-up to this message"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
Post Follow-up to this messageHey, 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
Post Follow-up to this messageHey, 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
Post Follow-up to this messagetemplate <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
>
>
Post Follow-up to this messagewhy 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
>
>
Post Follow-up to this messageThanks 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.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.