scwwarriors's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 7 (0.01 per day)
- Joined:
- 15-October 11
- Profile Views:
- 83
- Last Active:
Nov 06 2011 09:34 AM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: errors with function
Posted 15 Oct 2011
blackcompe, on 15 October 2011 - 11:54 AM, said:I just told you exactly what you need to do. Rename val to the corresponding field in the Node class.
const T& top() { return getHeadPtr()->val; }
It should compile without error. It would also be helpful to post your NODE class.
I did not see your post!! sorry
and I did
const T& top() { return LINKED_LIST<T>::getHeadPtr()->m_data; }
it compiled.
thank you -
In Topic: errors with function
Posted 15 Oct 2011
Okay I'll just post what I have.
Here is my LINKED_LIST.h
#ifndef LINKED_LIST_H #define LINKED_LIST_H #include "ORDERED_COLLECTION.h" #include "NODE.h" template <class T> class LINKED_LIST: public ORDERED_COLLECTION<T> { public: LINKED_LIST(): m_head(NULL),m_tail(NULL) {} LINKED_LIST(const LINKED_LIST<T>& cpy): m_head(NULL),m_tail(NULL) {*this = cpy;} ~LINKED_LIST() { clear(); } void insertAtHead(const T& ins); void insertAtTail(const T& ins); void removeAtHead(); void removeAtTail(); bool find(const T& f) const; bool removeFirstOccurrence(const T& rem); unsigned int removeAllOccurrences(const T& rem); void clear(); LINKED_LIST<T>& operator=(const LINKED_LIST<T>& rhs); bool operator== (const LINKED_LIST<T>& rhs) const; NODE<T>* getHeadPtr() {return m_head;} NODE<T>* getTailPtr() {return m_tail;} protected: NODE<T>* m_head, *m_tail; }; #include "LINKED_LIST.hpp"
here is my STACK.h
#ifndef STACK_H #define STACK_H #include "LINKED_LIST.h" template <class T> class STACK : protected LINKED_LIST<T> { public: const T& top() { LINKED_LIST<T>::getHeadPtr();} void push(const T& ins) { LINKED_LIST<T>::insertAtHead(ins); } void pop() { LINKED_LIST<T>::removeAtHead();} LINKED_LIST<T>& operator=(const LINKED_LIST<T>& rhs); bool operator== (const LINKED_LIST<T>& rhs) const; }; #endif
I know for a fact that my push and pop functions are correct. the = and == functions are also correct.
I need my top function to do the same thing as my getHeadPtr function. I need it to not only return m_head but also what m_head is pointing to. I'm still not understanding what I need to do to make this happen.
Sorry I probably wasn't very clear in the first post. -
In Topic: errors with function
Posted 15 Oct 2011
sk1v3r, on 15 October 2011 - 11:27 AM, said:LINKED_LIST<T>::getHeadPtr()
This is a function call. Is it meant to be here?
Why do you then open up curly brackets?
Also, you cannot return two values from a function.
Maybe it would help if you are telling us what you want to do. And what do mean by "this is a function that I wrote from another class"?
Yes I need my top function to do the same thing as my getHeadPtr function that I have in another file.
I just I don't need to open up curly brackets again if I already have the function implemented in another file, right?
this is what that function looks like in LINKED_LIST.h
NODE<T>* getHeadPtr() {return m_head;}
so should my function in STACK.h just look like this?
const T& top() { LINKED_LIST<T>::getHeadPtr();}
with this I get no errors and it makes more sense. -
In Topic: call a function from one class to use in another inheritance hierarchy
Posted 15 Oct 2011
#ifndef STACK_H #define STACK_H #include "LINKED_LIST.h" template <class T> class STACK : protected LINKED_LIST<T> { public: const T& top() { LINKED_LIST<T>::getHeadPtr() {return m_head;}} void push(const T& ins) { LINKED_LIST<T>::insertAtHead(ins); } void pop() { LINKED_LIST<T>::removeAtHead();} LINKED_LIST<T>& operator=(const LINKED_LIST<T>& rhs); bool operator== (const LINKED_LIST<T>& rhs) const; }; #endif
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
scwwarriors hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
scwwarriors has no profile comments yet. Why not say hello?