Jul 30, 2011 at 9:43pm Jul 30, 2011 at 9:43pm UTC
Any function that returns a
D_Node requires a type-specifier. For example:
const D_Node< Item > *fore( ) const ;
Wazzak
Last edited on Jul 30, 2011 at 9:43pm Jul 30, 2011 at 9:43pm UTC
Jul 30, 2011 at 9:56pm Jul 30, 2011 at 9:56pm UTC
Thanks. However, I don't understand how to implement this advice. How does this change my function call of:
previous_ptr = dlist_search(head_ptr, 3);
I appreciate your help.
Jul 30, 2011 at 10:05pm Jul 30, 2011 at 10:05pm UTC
Placing < int > after the function identifier and before the parameter list may solve your problem. For example:
previous_ptr = dlist_search< int >(head_ptr, 3);
Some compilers may know the type it's working with automatically, but yours may not.
Wazzak
Last edited on Jul 30, 2011 at 10:05pm Jul 30, 2011 at 10:05pm UTC
Jul 30, 2011 at 10:06pm Jul 30, 2011 at 10:06pm UTC
Actually, I think that it changes the function prototype, but I can't figure out the syntax.
Jul 30, 2011 at 10:18pm Jul 30, 2011 at 10:18pm UTC
I see at least two things that need to be fixed.
(1) Your function's return type. It's D_Node<Item>
while it should be D_Node<Item> *
(2) The second argument to your function. It should be const Item & target
(a) since you can't bind a literal constant (the number '3') to a non - const reference and
(b) if you want to be const correct, since your function doesn't modify 'target' anyway.
Also, this line -> previous_ptr = new D_Node<int >;
is unnecessary,
but it won't cause you any trouble other than a minor memory leak.
Last edited on Jul 30, 2011 at 10:32pm Jul 30, 2011 at 10:32pm UTC
Jul 30, 2011 at 10:27pm Jul 30, 2011 at 10:27pm UTC
It works!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I can't tell you how much time I have spent on this and how much I appreciate your help.
Thanks a million!