473,566 Members | 3,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

smart pointer problem

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<ML inkedList<int>: :ListNode>', because the type is not yet
defined in function MLinkedList
<int>::~MLinked List()
Error E2315 mlinkedlist.h 70: 'object' is not a member of
'counted_ptr<ML inkedList<int>: :ListNode>', because the type is not yet
defined in function MLinkedList
<int>::~MLinked List()
Error E2315 mlinkedlist.h 72: 'next' is not a member of
'counted_ptr<ML inkedList<int>: :ListNode>', because the type is not yet
defined in function MLinkedList<i
nt>::~MLinkedLi st()

----------------------------------------------------
template <class T>
MLinkedList<T>: :~MLinkedList()
{
counted_ptr<Lis tNode> *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<Lis tNode> *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<MLi nkedList<T>::Li stNode> *first_;
counted_ptr<MLi nkedList<T>::Li stNode> *current_;
int size_;
----------------------------------------------------

best regards,

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

Jul 22 '05 #1
1 1868

"Marko Pyhajarvi" <Ma************ ***********@cs. helsinki.fi> skrev i en
meddelelse news:bq******** **@newstree.wis e.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<ML inkedList<int>: :ListNode>', because the type is not yet
defined in function MLinkedList
<int>::~MLinked List()
Error E2315 mlinkedlist.h 70: 'object' is not a member of
'counted_ptr<ML inkedList<int>: :ListNode>', because the type is not yet
defined in function MLinkedList
<int>::~MLinked List()
Error E2315 mlinkedlist.h 72: 'next' is not a member of
'counted_ptr<ML inkedList<int>: :ListNode>', because the type is not yet
defined in function MLinkedList<i
nt>::~MLinkedLi st()

[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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1795
by: Johnny Hansen | last post by:
Hello, I've been trying to implement smart pointers in C++ (combined with a reference counter) because I want to do some memory management. My code is based on the gamedev enginuity articles, various books and ... whatever I could find on the subject :-) I'll leave out the reference counter part because its pretty basic, but my reference...
24
2177
by: Christopher Benson-Manica | last post by:
Is there anything wrong with my attempt (below) at implementing something resembling a smart pointer? template < class T > class SmartPointer { private: T *t; public:
27
3368
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined as ff: typedef struct { float *data ; int count ;
8
5124
by: Axter | last post by:
I normally use a program call Doxygen to document my source code.(http://www.stack.nl/~dimitri/doxygen) This method works great for small and medium size projects, and you can get good documentation like the following: http://axter.com/smartptr Now I'm on a client site, and I'm trying to create the same type of documentation on a very...
6
2294
by: zl2k | last post by:
hi, When I considered about preventing memory leaking, the method came up to my mind is using boost smart pointer if possible (use stl::vector instead of type, use smart pointer whenever declare an instance of class). With the container of STL, this may often result in a vector of smart pointers, or a smart pointer of STL container. Am I...
16
4112
by: Yong Hu | last post by:
Does the smart pointer never lead to memory leak? Thanks,
33
5024
by: Ney André de Mello Zunino | last post by:
Hello. I have written a simple reference-counting smart pointer class template called RefCountPtr<T>. It works in conjunction with another class, ReferenceCountable, which is responsible for the actual counting. Here is the latter's definition: // --- Begin ReferenceCountable.h ---------- class ReferenceCountable
54
11918
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining the advantages of smart pointers endlessly (which are currently used in all our C++ software; we use the Boost smart pointers) as I'm seriously...
7
2124
by: sip.address | last post by:
I'm using reference counted smart pointers in a small project and it's a breeze, but I'm running into a problem which I don't know how to approach. Consider something like this: class A { public: A() {} void setObserver(counted_ptr<Bobserver) { _observer =
13
2054
by: Phil Bouchard | last post by:
I am currently writting a smart pointer which is reasonnably stable and I decided supporting allocators for completion because of its increase in efficiency when the same pool used by containers is shared. I was told the new standards are being finalized and I am hoping minor but important changes could be applied before anything else. To...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.