| | |
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 array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





