User Profile
Collapse
-
Deconstructors
When you create a template class, what do you do about deconstructors?
Given the class below I added ~DLNode(){}; after the constructor, but when I ran some tests it didn't seem to ever fire when then main program ended.
Can anyone shed some light on this?
Code:template <class Type> class DLNode{ public: DLNode(Type elem, DLNode* prev, DLNode* next){ data = elem;
-
Yeah. The thought that prompted the question was was imagining a huge class or series of classes where you have a mass of both pointers and variables and it gets hard to remember what is what.
Is it safe to say that basic types are most often left as variables while objects are pointers or is that too often not the case?...Leave a comment:
-
-
I am actually asking about the node here, not the whole tree so let me take a different approach. In the class below is there any reason I should define 'element' as a pointer instead? (i.e. Type* element)
In fact, what I am really trying to do is ask a general question about when to use a variable and when to use a pointer. I just gave an example to hopefully make the question clearer.
Code:template <class Type>
Leave a comment:
-
Sorry. Typo. What I meant was doubly-linked nodes, not a list.
In any case, it was just an example and the question is about variables/pointers....Leave a comment:
-
Question about variables
Suppose I am creating a binary tree data structure using a double linked list. each node of the linked list will have an element and a pointer to two other nodes.
In this instance my question is should I declare the element as a pointer like the pointers to the two other nodes or as a variable?
My more general question is are there any conventions as to when to use a variable and when to use a pointer?
... -
Thank you. What I was really looking for though was an explanation on the difference between something like int* a and int *a. Why is the '*' sometimes on the variable name and sometimes on the type?Leave a comment:
-
Easy syntax question
Is there a difference between
void DLNode::setNext (DLNode* node){} or int* a
and
void DLNode<Type>::s etNext(DLNode *node){} or int *a
I've seen both used, is it just a style thing or is there some difference? -
Problem solved: DLNode<int> *intlist = new DLNode<int>(a);
DOH...Leave a comment:
-
Ok, I did some more digging and it is not a problem with the templates it is a problem with the classes. I assume "first" has gone out of scope after the addNode method??? (note I took out the templates stuff for readability)
Code:#include <stdio.h> #include "DLListint.h" main(){ DLListint intlist; intlist.addNode(9); printf("%d", intlist.getFirst());
Leave a comment:
-
A Sequence is an ADT that models, well a sequence of something. If you imagine a line of people holding hands you would have a "sequence" of people.
If you further imagine the line grows from left to right then you can imagine two things. First, every person has a number which is how many places they are from the left (this is their rank). Second, everyone has someone (or the end of the sequence) to the left and to the right...Leave a comment:
-
Thanks for the help. I moved everything into the header file butnow I seem to have a problem accessing data. intlist.getFirs t() doesn't return the data. I first thought this was a problem with DLList accessing DLNode methods and tried adding it as a friend to DLNode but got the same results.
Again, this must be something trivial?
Code:#include <stdio.h> #include "DLList.h" main(){
Leave a comment:
-
Trouble with Template classes
Hi. I'm trying to write series of classes using templates and am running into what must be a simple error. I'm a bit of a noob so I apologize in advance if this kind of question is not welcome here.
When I try to run the program below i get the following error during build (using Visual Studio).
Data Structures error LNK2019: unresolved external symbol "public: __thiscall DLNode<int>::DL Node<int>(int)"...
No activity results to display
Show More
Leave a comment: