Skip to main content
10 events
when toggle format what by license comment
Jun 17, 2016 at 15:04 comment added JRobert @Raed: About "understanding when to use * or ->": *pointer means the thing pointer points to. It could be a simple entity like a number, or a whole bunch (tech term, heh) of entities like an array or a struct or a class. pointer->foo means the member named foo within the thing pointer points to. (In this case the "thing" would have to be a struct, a union, or a class, to have named members).
Jun 17, 2016 at 14:39 history edited Code Gorilla CC BY-SA 3.0
Change answer to say you can have a referance within a class.
Jun 17, 2016 at 14:34 comment added Code Gorilla @Raed Its difficult to guess your code, but assuming this is a simple class, I don't think you need to use a * except in the declaration of variables where it declares a pointer. In the code pointer will give you the data that is pointed to by pointer, which you can access with ->. You use new to allocate memory CElement pNewObject = new CElement(); and delete pNewObject should be all you need. However I would recommend that you check that pNewObject has been allocated after the new and before the delete calls. if (!pNewObject) // If not allocated report error.
Jun 17, 2016 at 14:33 comment added John Burger @Matt Why do you think you can't have it as a reference? It may not be useful (in this instance), but it's certainly legal.
Jun 17, 2016 at 14:30 comment added Code Gorilla @JohnBurger - Thanks, good spot. My fingers were traveling faster than my brain. Hopefully corrected them now.
Jun 17, 2016 at 14:29 history edited Code Gorilla CC BY-SA 3.0
Typos
Jun 17, 2016 at 14:22 comment added Raed @Matt thanks, I added the forward declaration to my Node class. while i did manage to solve this I'm having a lot of trouble understanding when to use * or -> and new keyWord
Jun 17, 2016 at 13:11 comment added John Burger Also, check your "Just to be clear" line: you say "you can have your class as a member variable" - you mean "you can't". If you want you can have it as a reference - you imply you can't.
Jun 17, 2016 at 13:10 comment added John Burger You don't actually need to pre-declare the class the way you did on your first line: the class CElement is known about by the time the compiler gets to the CElement *m_NextElement; line
Jun 17, 2016 at 12:04 history answered Code Gorilla CC BY-SA 3.0