How can I manually (other then http://www.boost.org/libs/smart_ptr/...from_this.html)
create a shared, and a weak pointer to "this"?
Of course I dont want the shared / weak pointer to cause object to be
deleted when shared/weak ptr will go out of scope.
--
Wymiana starych układów... na nowe układy - prawie jak walka z korupcja.
Walka z wychowaniem seksualnym i erotykÄ… - prawie jak walka z patologiÄ….
PiS - prawie jak prawo i sprawiedliwoÅ›Ä ‡... Prawie. Prawie robi różnicÄ™.
Myśl. Głosuj rozsądnie. Nie na tanie hasła. // Rafał Maj Raf256 2 3812
In article <e0**********@i news.gazeta.pl> ,
Rafa©© Maj Raf256 <us************ *******@raf256. com.invalid> wrote: How can I manually (other then http://www.boost.org/libs/smart_ptr/...from_this.html) create a shared, and a weak pointer to "this"?
Of course I dont want the shared / weak pointer to cause object to be deleted when shared/weak ptr will go out of scope.
That's the major problem with shaired pointers IMO. I have a class that
doesn't have this problem. I store the reference counts in a map<void*,
int>
That way, both pointer objects in the code below increment the same
reference count.
class MyClass {
public:
void doThis() {
Ptr<MyClass> p( this );
// ...
}
};
void func( Ptr<MyClass> foo ) {
foo->doThis();
}
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
"Rafal Maj Raf256" <us************ *******@raf256. com.invalid> wrote in
message news:e0******** **@inews.gazeta .pl... How can I manually (other then http://www.boost.org/libs/smart_ptr/...from_this.html) create a shared, and a weak pointer to "this"?
Of course I dont want the shared / weak pointer to cause object to be deleted when shared/weak ptr will go out of scope.
If you know that your object is long lived, you can do the following:
struct null_deleter
{
template <class T> void operator()(T *) {}
}
Then in your code, just return a shared_ptr<your _type>(this, null_deleter())
Joe Gottman This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ernst Murnleitner |
last post by:
Dear Readers,
Is it possible to forbid conversion from this or use of this in general
except where it is explicitly wanted?
Reason:
I changed my program from using normal pointers to classes A, ...
typedef A * APtr;
|
by: solosnake |
last post by:
Whilst browsing Flipcode I noticed this code:
class CConsole: public I_TextOutput
{
public:
...
void Release() { delete this; }
...
};
|
by: JKop |
last post by:
You can overload the address-of operator. Consider a simple class:
class Blah
{
public:
Blah* operator&()
{
return this;
}
|
by: Joseph Turian |
last post by:
Fellow hackers,
I have a class BuildNode that inherits from class Node.
Similarly, I have a class BuildTree that inherits from class Tree.
Tree includes a member variable:
vector<Node> nodes; // For clarity, let this be "orig_nodes"
BuildTree includes a member variable:
|
by: Alf P. Steinbach |
last post by:
So, I got the itch to write something more...
I apologize for not doing more on the attempted "Correct C++ Tutorial"
earlier, but there were reasons.
This is an UNFINISHED and RAW document, and at the end there is even pure
mindstorming text left in, but already I think it can be very useful.
<url: http://home.no.net/dubjai/win32cpptut/special/pointers/preview/pointers_01__alpha.doc.pdf>.
| |
by: Alf P. Steinbach |
last post by:
Not yet perfect, but:
http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf
http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip
To access the table of contents, use the "Bookmarks" tab in Adobe
Acrobat.
Comments, corrections, praise, nits, etc., are still welcome!
|
by: for.fun |
last post by:
Hi everybody,
I have the following problem :
B class need A::MyEnum type and A class need B::MyEnum type.
In both case, the class type is incomplete so it is obvious that the
::MyEnum can not be found in the class definition (the compiler
complains)
My problem is the MyEnum types have to be defined inside the class
|
by: Joe |
last post by:
usually slide bars move by "jumps" while scrolling which looks not
nice.
I came accress slide bar with price menu, ewnt through script/web
source code, and could not find anything that would case that wanted
effect :)
here you go:
http://www.shopping.hp.com/webapp/shopping/computer_can_series.do?storeName=computer_store&category=notebooks&a1=Display&v1=20.1&series_name=HDX_series&a1=Display&v1=20.1
click on the left >Recommended config...
|
by: Daniel Pitts |
last post by:
I have std::vector<Base *bases;
I'd like to do something like:
std::for_each(bases.begin(), bases.end(), operator delete);
Is it possible without writing an adapter? Is there a better way? Is
there an existing adapter?
Thanks,
Daniel.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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,...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |