473,395 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 5404

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::intrusive_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::intrusive_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::intrusive_ptr<T>

Oct 5 '05 #4

Pradeep wrote:
When i do

pass( boost::intrusive_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::intrusive_ptr<T>


I believe you want to write:

pass( boost::intrusive_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::intrusive_ptr<T>

the definition of the method is

void pass(const BPtr& bptr)

where BPtr is typedef boost::intrusive_ptr<B> BPtr;

Oct 5 '05 #6

Pradeep wrote:
When i do

pass( boost::intrusive_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
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...
9
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...
4
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...
1
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...
5
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...
204
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 =...
51
by: Joe Van Dyk | last post by:
When you delete a pointer, you should set it to NULL, right? Joe
2
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.