Re: pointer and smart pointer address Programming Software Development by Ravalon [QUOTE]How do I get smart pointer from pointer address?[/QUOTE] You can't. Smart pointers are smart, but regular pointers are very dumb…::get() gives you a dumb pointer that points to the memory paired with the smart pointer. The memory is the same,… so you can pass that dumb pointer to the API … pointer and smart pointer address Programming Software Development by l2u … { public: char test; }; typedef boost::shared_ptr<someclass> someclass_p; //smart pointer int main() { someclass_p testp = someclass_p( new someclass() ); ULONG_PTR uptr = (…ULONG_PTR)testp.get(); //so I have pointer address here //How do I get testp from uptr? return… Re: pointer initialization in assignment operator Programming Software Development by Banfa … you could make your class safer by not passing a pointer in the constructor at all, if it needs to use… a pointer internally that is fine, pass an int by value and…. If the design requires that the pointer is passed in then use a smart pointer and let the pointer handle the memory deallocation. Problem… Re: Smart Pointers assignment Programming Software Development by Alex Edwards … methods/operations such that the smart pointer is treated like a const smart pointer (and obviously a smart pointer to a const would have…via new, but if needed you can force your smart pointer to accept types that implement a common class with …method and a std::size_t size() method for your smart pointer class. I'm sure there are plenty of other … Re: pointer deletion without memory allocation. Programming Software Development by rubberman …iostream> using namespace std; // A generic smart pointer class template <class T> class …SmartPtr { T *ptr; // Actual pointer public: // Constructor SmartPtr(T* p = NULL) : ptr… item is deleted, but another smart pointer is still holding onto it... Crash!… pointer deletion without memory allocation. Programming Software Development by can-mohan …are not allocating any memory in smart pointer constructer for ptr but still delete…> using namespace std; // A generic smart pointer class template <class T> class SmartPtr… { T *ptr; // Actual pointer public: // Constructor explicit SmartPtr(T *p = NULL) { … Smart Pointers Programming Software Development by triumphost …I had to use .get() to pass my pointer to fread and various other functions. My problem comes…pFile, Buffer, dwHeader); pFile = (char*)((DWORD)pFile + jmpSize); //Smart ptr.. :S I'm confused.. std::shared_ptr<char[]>…in time where I should use a Smart pointer vs. a Raw pointer (Referring to a bitmap class where … Re: pointer deletion without memory allocation. Programming Software Development by rubberman … when you assign an object to a smart pointer, it's ownership is passed to the smart pointer. Caveat. If the object is on… Re: pointer deletion without memory allocation. Programming Software Development by can-mohan Thanks rubberman for your replay . I didn't share entire smart pointer implementation as it won't help me to focus on … Smart Pointers assignment Programming Software Development by c++_student Can anyone help me with a computer science C++ assignment that i am struggling with? The task is to design and implement a generic reference counted smart pointer class library, and use the smart pointers to create a smart generic linked list class... any help would be greatly appreciated... Thanks Re: Assignment doesn't work between pointer objects Programming Software Development by can-mohan … hence assignment was necessary .It is always suggested to use smart pointer instead of raw pointers . I believe it answers your below… Beginning C++0x: Design of Ownership Programming Software Development by mike_2000_17 …cycle). The solution to both problems involves another smart-pointer that is the natural companion of [ICODE]shared_ptr…the header [ICODE]<memory>[/ICODE]. This smart-pointer implements unique ownership and automatic behavior, in other…to when it is itself destroyed. This new smart-pointer replaces the deprecated [ICODE]auto_ptr[/ICODE] class … Re: Test if variable (or pointer) was initialized Programming Software Development by Ancient Dragon … write your own or use an existing smart pointer c++ class. google for "c++ smart pointer" and you will find examples and… Re: STL - Pointer to container Question Programming Software Development by StuXYZ …There are several "obvious" reasons for having a pointer, e.g. (a) you could have extended a standard … you want (and slightly more optimization), by moving the pointer one level higher. E.g. Making the it [icode… Personally, I prefer to put those pointers in a smart pointer like boost::shared_ptr. That way you get the optimization you… Re: delete a pointer inside of a method Programming Software Development by sbmcdeshan [QUOTE=Tom Gunn;1028862]The [I]destructor[/I], yes. Or better yet, use a smart pointer like auto_ptr where you do not need to worry about deleting it at all.[/QUOTE] ya ya it's destructor. And thank You very much for giving me the answer and this new thing call smart pointer. :) Re: Difference between call by reference and call by pointer Programming Software Development by mike_2000_17 … = 42; }; void set_to_69(int* value) { //pass-by-pointer *value = 69; //notice the dereferencing with * in front of… typical with pointers (like mistakenly re-seating a pointer). Moreover, this feature also makes references non-assignable…++ programmers prefer the use of a smart-pointer instead of a raw-pointer (the use-cases of raw-pointers… Re: Has Pointer Member but does not override.. Programming Software Development by mike_2000_17 …;. This just means that it is essentially a pointer but you have no idea what it points to, and …"). If you library from which you got the opaque pointer does not have a method to copy (or duplicate) the… of the code to access that object, then use a smart-pointer, like `std::shared_ptr<Foo>`. Re: delete a pointer inside of a method Programming Software Development by Tom Gunn [QUOTE]Should I put delete in the constructor of that class[/QUOTE] The [I]destructor[/I], yes. Or better yet, use a smart pointer like auto_ptr where you do not need to worry about deleting it at all. Re: Simple pointer program crashses Programming Software Development by Rashakil Fol … could be dangerous because if the 'variable' I told the pointer to attach to goes away, the rest of the program… pointers are reasonable to use in place of iterators and smart pointer classes. Need feedback on shared_ptr and weak_ptr usage for resource manager Programming Software Development by NordCoder … my choice of implementation and design. Am I using the smart pointers in a correct way? Am I overcomplicating things? etc…; does not exist\n"; return ResourcePtr(); // "Empty" smart pointer, should throw exception instead in the future though } return ResourcePtr… Re: problem when trying to use a copy constuctor Programming Software Development by CrazyDieter … name for this kind of classes is "smart pointer". it acts like a pointer, but automatically destroys the object when not… problem when trying to use a copy constuctor Programming Software Development by CrazyDieter …; for my programs, I'm trying to write a template smart-pointer class, that may be used like that : [code] #include <… Re: C++ 11, g++, and pointers Programming Software Development by mike_2000_17 … These components are called smart-pointers. The `std::unique_ptr` allows you to create a pointer to dynamically allocated memory…, wrap it inside that unique-pointer and whenever the unique-pointer goes out of scope (e.g.,…The `std::shared_ptr` is another smart-pointer that works similarly to the unique-pointer except that it keeps a reference… Re: Strange memory corruption issue when using g++ Programming Software Development by ravenous … store value in smart pointer, lets say you you store a in the smart pointer, even b fails, smart pointer will take care …of memory deallocation of a[/quote] Yeah, a smart pointer is …generally safer than using a raw pointer, but I didn't want … Re: "delete this" Programming Software Development by mike_2000_17 … few options. I would suggest using a smart pointer and a factory function. The smart pointer will make sure that your class has sole…>& Create() { return (new myclass())->mThis; //return the smart pointer. }; //public destructor function: void Destroy() { boost::scoped_ptr<myclass>… Re: Scope-guarded lockable objects in C++11 Programming Software Development by mike_2000_17 …-move-assignable // Implicit conversion to the corresponding const smart-pointer: operator locked_ptr_impl<const T>() { return … allowed by friendship. }; // Friendship with non-const smart-pointer: friend class locked_ptr_impl< typename std::remove_const<T… Re: Strange memory corruption issue when using g++ Programming Software Development by alwaysLearning0 … you store value in smart pointer, lets say you you store a in the smart pointer, even b fails, smart pointer will take care of memory… Re: Indestructible Pointers or Modifiable Const Containers. Programming Software Development by mike_2000_17 …to be deleted; - The allocated memory is managed by a smart-pointer (e.g., unique_ptr or shared_ptr), which means that the …deletion logic is bundled with the pointer, and will be invoked automatically; - At worse, you can… all. This can certainly be done with a simple smart-pointer, but, as I said, you don't need to… Re: Assignment of pointers to templated class objects using different template arguments Programming Software Development by biggie_smalls … my_pT, but you have specified my_pT as a const pointer, not a pointer to a const object, which prevents you re-assigning…. It reproduces what is actually happening in the more complex smart pointer class. Re: Pointers and Memory Programming Software Development by pseudorandom21 …?.. nvm) [/quote] [i]Yes.[/i] If you're assigning a pointer the address of a stack allocated variable you need worry… properly delete it, and with your current ideas a smart pointer is totally superior for that. But in theory/practice you … it goes out of scope. The standard library has a smart pointer type, it's the std::auto_ptr<> [b]BUT…