By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

smart pointer problem

P: n/a
good morning,

could anyone help me with this problem? i have made an abstract
container from which i have inherited a linkedlist class. this
linkedlist uses a smart pointer "counted_ptr<T>". there is a problem
now, that destructor definition doesn't go through compilation. below is
the code and comment from the compiler.

the problem seems to be that in destructor pointers next_ and object_
are not members of counted_ptr. what confuses me is that this same
doesn't appear in function "clear()" below!!?? i really don't get
understand anymore. do you know where i have made wrong? below is also
the struct which is located inside the linkedlist class.

Error E2315 mlinkedlist.h 69: 'object' is not a member of
'counted_ptr<MLinkedList<int>::ListNode>', because the type is not yet
defined in function MLinkedList
<int>::~MLinkedList()
Error E2315 mlinkedlist.h 70: 'object' is not a member of
'counted_ptr<MLinkedList<int>::ListNode>', because the type is not yet
defined in function MLinkedList
<int>::~MLinkedList()
Error E2315 mlinkedlist.h 72: 'next' is not a member of
'counted_ptr<MLinkedList<int>::ListNode>', because the type is not yet
defined in function MLinkedList<i
nt>::~MLinkedList()

----------------------------------------------------
template <class T>
MLinkedList<T>::~MLinkedList()
{
counted_ptr<ListNode> *removal;
current_ = first_;
while (current_ != 0)
{
if (current_->object != 0)
delete current_->object;
removal = current_;
current_ = current_->next;
delete removal;
removal = 0;
}
}

template <class T>
void MLinkedList<T>::clear()
{
counted_ptr<ListNode> *removal;
current_ = first_;
while (current_ != 0)
{
removal = current_;
current_ = current_->next;
delete removal;
removal = 0;
}
}

struct ListNode
{
T *object;
ListNode *next;
ListNode *previous;
};
counted_ptr<MLinkedList<T>::ListNode> *first_;
counted_ptr<MLinkedList<T>::ListNode> *current_;
int size_;
----------------------------------------------------

best regards,

--
Marko Pyhäjärvi
ma*************@iki.fi
http://www.iki.fi/~marko.pyhajarvi

Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Marko Pyhajarvi" <Ma***********************@cs.helsinki.fi> skrev i en
meddelelse news:bq**********@newstree.wise.edt.ericsson.se...
good morning,

could anyone help me with this problem? i have made an abstract
container from which i have inherited a linkedlist class. this
linkedlist uses a smart pointer "counted_ptr<T>". there is a problem
now, that destructor definition doesn't go through compilation. below is
the code and comment from the compiler.

the problem seems to be that in destructor pointers next_ and object_
are not members of counted_ptr. what confuses me is that this same
doesn't appear in function "clear()" below!!?? i really don't get
understand anymore. do you know where i have made wrong? below is also
the struct which is located inside the linkedlist class.

Error E2315 mlinkedlist.h 69: 'object' is not a member of
'counted_ptr<MLinkedList<int>::ListNode>', because the type is not yet
defined in function MLinkedList
<int>::~MLinkedList()
Error E2315 mlinkedlist.h 70: 'object' is not a member of
'counted_ptr<MLinkedList<int>::ListNode>', because the type is not yet
defined in function MLinkedList
<int>::~MLinkedList()
Error E2315 mlinkedlist.h 72: 'next' is not a member of
'counted_ptr<MLinkedList<int>::ListNode>', because the type is not yet
defined in function MLinkedList<i
nt>::~MLinkedList()

[snip]

Error E2315 indicates that you have a forward declaration of the class
object:

class object;

In this case there is not much you can do with a variable of that type.
Specifically you can not delete an object of this type:
object *o; // legal
delete o; // illegal - as is (btw) o = new object;

Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.