473,776 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Intrusive pointer problem

Hi,

I am using intrusive pointers for my code but i am not much aquianted
with them. I am using an example to illustrate my problem as i can't
share the code.

I have two clases ( say A and B)
B is derived from A( B: public A)

now i want to pass the this* pointer of the derived class(B) to a
method of an object that takes intrusive pointer of the base class(A)
as argument.

method definition
pass(intrusive_ ptr<A>)
and i am passingt the this pointer of class B.

I have tried using dynamic_cast as well as dynamic_pointer _cast but i
still get the error.

Thanks in Advance.
Pradeep

Oct 5 '05 #1
6 5427

Pradeep wrote:
Hi,

I am using intrusive pointers for my code but i am not much aquianted
with them. I am using an example to illustrate my problem as i can't
share the code.

I have two clases ( say A and B)
B is derived from A( B: public A)

now i want to pass the this* pointer of the derived class(B) to a
method of an object that takes intrusive pointer of the base class(A)
as argument.

method definition
pass(intrusive_ ptr<A>)
and i am passingt the this pointer of class B.

I have tried using dynamic_cast as well as dynamic_pointer _cast but i
still get the error.


With boost::intrusiv e_ptr<> it should work.

You might like posting a complete example, so that people here can see
the behaviour you observe.

Oct 5 '05 #2

Pradeep wrote:
Hi,

I am using intrusive pointers for my code but i am not much aquianted
with them. I am using an example to illustrate my problem as i can't
share the code.

I have two clases ( say A and B)
B is derived from A( B: public A)

now i want to pass the this* pointer of the derived class(B) to a
method of an object that takes intrusive pointer of the base class(A)
as argument.

method definition
pass(intrusive_ ptr<A>)
and i am passingt the this pointer of class B.

I have tried using dynamic_cast as well as dynamic_pointer _cast but i
still get the error.


What error?

Greg

Oct 5 '05 #3
When i do

pass( boost::intrusiv e_ptr<A> (*this));

where A is the derived class while the argument for the method is
intusive pointer to the base class

I get the error C2440: Cannot convert from const A to
boost::intrusiv e_ptr<T>

Oct 5 '05 #4

Pradeep wrote:
When i do

pass( boost::intrusiv e_ptr<A> (*this));

where A is the derived class while the argument for the method is
intusive pointer to the base class

I get the error C2440: Cannot convert from const A to
boost::intrusiv e_ptr<T>


I believe you want to write:

pass( boost::intrusiv e_ptr<A>(this)) ;

or even

pass(this);

Smart pointers are constructed from pointers - "this" is a pointer,
"*this" is a value.

Greg

Oct 5 '05 #5
Thanks Greg.

I change the this* to this. However i still get the error. 2440 -
cannot convert frm A *const to boost::intrusiv e_ptr<T>

the definition of the method is

void pass(const BPtr& bptr)

where BPtr is typedef boost::intrusiv e_ptr<B> BPtr;

Oct 5 '05 #6

Pradeep wrote:
When i do

pass( boost::intrusiv e_ptr<A> (*this));

where A is the derived class while the argument for the method is
intusive pointer to the base class


There is no implicit conversion from a base class pointer to a derived
one.
You have to cast it explicitly:

struct A {}; struct B : A {};
void foo(B*);

A* a;
foo(static_cast <B*>(a));

Oct 5 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1450
by: Sabyasachi Basu | last post by:
Most C++ object serialization techniques are intrusive, that is they require all serializable classes need to have functions to stream in and stream out their contents. I came across "non-intrusive serialization" while going through the tutorial on Robert Ramey's serialization library for Boost. However, it is not clear to me how to implement serialization without the cooperation of the classes being serialized. Can someone through...
9
4056
by: Marcin Kalicinski | last post by:
Hi everybody, I am creating an intrusive list ('next' and 'prev' pointers are stored within an object that is in a list). One method of doing that is to inherit all objects from some class that contains these pointers. However, it is unacceptable for my problem, because it limits the number of lists the object can be in to 1. I must have some objects in more than 1 list. Instead of inheriting, I use aggregation: class Node { //...
4
2143
by: Carsten Spieß | last post by:
Hello all, i have a problem with a template constructor I reduced my code to the following (compiled with gcc 2.7.2) to show my problem: // a base class class Base{}; // two derived classes
1
1624
by: Pradeep | last post by:
Hi, I am working with Intrusive pointers in a DLL and I need to set the value of the intrusive pointer to an object to NULL from inside the method of that class. So here's the scenario. I have a class A which has a method del().
5
6062
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user hits the right and left keys to move this insertion point (cursor) Here is the problem:
204
13107
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 = {0,1,2,4,9};
51
10482
by: Joe Van Dyk | last post by:
When you delete a pointer, you should set it to NULL, right? Joe
2
2845
by: toton | last post by:
Hi, This is continuation of topic pointer & reference doubt. http://groups.google.com/group/comp.lang.c++/browse_thread/thread/df84ce6b9af561f9/76304d7d77f6ccca?lnk=raot#76304d7d77f6ccca But I think it is better to have a new topic rather than continuing on old one. As now I am sure pointer to reference and reference to pointer are freely convertable, the potential danger lies in the first one. Pointer may be NULL, but reference should...
2
2923
by: Steven T. Hatton | last post by:
It's my understanding that intrusive pointers are frowned upon. For example this is from the boost::intrusive_ptr documentation: "As a general rule, if it isn't obvious whether intrusive_ptr better fits your needs than shared_ptr, try a shared_ptr-based design first." This tells me that intrusive pointers are faster and leaner than any of the other alternative other than raw pointers. http://www.boost.org/libs/smart_ptr/smarttests.htm ...
0
10120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8952
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5367
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
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
3
2860
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.