| | |
Pointer Question
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I am stuck on something that I know is so simple that I can't figure it out...
I have a BST class, and a private item:
Any help is greatly appreciated!!! After a certain point I tried every combination of &* that I could think of, ie: root = *n; *root=n; *root=&n; *root=*n; ... etc, you get the point!
Any help is greatly appreciated!!!
I have a BST class, and a private item:
C++ Syntax (Toggle Plain Text)
Node<K> *root; // root pointer //and in a seperate class I have... template <typename K> class Node { public: // constructors Node() {}; Node(const K newKey, Node<K> *l, Node<K> *r) :key(newKey), left(l), right(r) {}; // data members K key; // key is a template Node<K> * left; // points to left child or NULL Node<K> * right; // points to right child or NULL }; //cut&paste some code Node<K> n; n.key = newKey; n.left = NULL; n.right = NULL; //so obviously there is a lot of cut&paste going on, but I assure you everything above this line works just fine. root = &n;
Any help is greatly appreciated!!! After a certain point I tried every combination of &* that I could think of, ie: root = *n; *root=n; *root=&n; *root=*n; ... etc, you get the point!
Any help is greatly appreciated!!!
You have created
Node<K> *root; before defining the class Node. Declare it after the class. Furthermore I dont think you can use Node<K> n; outside the class. You will have to specify a valid class or datatype instead of template K like Node<int> n; There are 10 types of people in the world, those who understand binary and those who don't.
All generalizations are wrong. Even this one.
All generalizations are wrong. Even this one.
•
•
Join Date: Nov 2006
Posts: 224
Reputation:
Solved Threads: 31
how about
C++ Syntax (Toggle Plain Text)
root = new Node<K>(newKey, NULL, NULL);
![]() |
Similar Threads
- Pointer question (C)
- Function with pointer? (C++)
- Easy (I hope) MIPS (SPIM) Question (Assembly)
- reading input ... quick C++ question ... (C++)
- A little Help (C++)
- This is my first Website. Constructive Criticism Is Welcome! (Website Reviews)
- Pointer Confusion (C++)
- typedef question (C)
Other Threads in the C++ Forum
- Previous Thread: Help with finishing a project
- Next Thread: cgi page reload problem
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion count data delete deploy dll download dynamic dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





