954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Calling a method from anther method

Hi, what I'm trying to do is call my validate() method from inside another method but it won't compile and I'm not sure why.. I'm pretty new at this.

Here is my validate():

ListNode* validate(const Position<T>* pos) const throw(PositionInvalidException) {
Position<T>* tmp = const_cast<Position<T>*>(pos);
ListNode* tmp2 = dynamic_cast<ListNode*>(tmp);
if (tmp2.head != NULL && tmp2 == ListNode().container_)
throw PositionInvalidException("position");
else
return tmp2->head();
}


and here is where I want to call it from:

virtual Position<T>* prev(const Position<T>* pos) const throw(ListBoundaryException, PositionInvalidException) {
ListNode* tmp = validate(pos);
return tmp->prev();
}


The error it gives is:

instantiated from `Position* ListDL:rev(const Position*) const [with T = std::string]'

and it refers to the "ListNode* tmp = validate(pos);" line.

I have no idea what the error means, Any hints or pointers would be muchly appreciated

jeebz88
Newbie Poster
3 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

>I have no idea what the error means
Neither do I, you only gave us part of it.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Oh sorry, here it is.

In member function `ListDL::ListNode* ListDL::validate(const Position*) const [with T = std::string]': instantiated from `Position* ListDL::prev(const Position*) const [with T = std::string]' instantiated from here comparison between distinct pointer types `ListDL::ListNode*' and `ListDL*' lacks a cast request for member `head' in `tmp2', which is of non-class type `ListDL::ListNode*'

jeebz88
Newbie Poster
3 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

Hi!

I think the function that u called do not able fine the return type, You can try this out, May it work.
ListNode* tmp = (ListNode*)validate(pos);

manojjena1982
Newbie Poster
22 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

Still gives the same error.. thanks tho

jeebz88
Newbie Poster
3 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You