Datasim Financial Forums Forum Index


 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
8. Smart Pointers

 
Post new topic   Reply to topic    Datasim Financial Forums Forum Index -> C++ Certification and Examinations: Advanced Level
View previous topic :: View next topic  
Author 8. Smart Pointers
Cuchulainn



Joined: 18 Dec 2006
Posts: 461
Location: Amsterdam, the Netherlands

PostPosted: Tue May 05, 2009 1:37 pm    Post subject: Reply with quote

Some exam questions on memory management, smart pointers. (Word 2003 and 2007).


ExercisesMemoryManagement.docx
 Description:

Download
 Filename:  ExercisesMemoryManagement.docx
 Filesize:  22.55 KB
 Downloaded:  146 Time(s)


ExercisesMemoryManagement.doc
 Description:

Download
 Filename:  ExercisesMemoryManagement.doc
 Filesize:  49.5 KB
 Downloaded:  459 Time(s)

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Cuchulainn



Joined: 18 Dec 2006
Posts: 461
Location: Amsterdam, the Netherlands

PostPosted: Sun Feb 01, 2009 11:51 am    Post subject: Reply with quote

Explain what is happening here:

// TestScopedPtr.cpp
//
// Testing scoped pointers in boost
//
// (C)Datasim Education BV 2008
//

#include "boost/scoped_ptr.hpp"
#include "Point.hpp"


int main()
{

{
// Create dynamic memory
boost::scoped_ptr <Point> myPoint (new Point(1.0, 23.3));

// Scoped pointer has same syntax as a raw pointer
if (myPoint != 0)
{
cout << *myPoint;
}

// Assign to another point
Point yourPoint (7.3, -9.9);

*myPoint = yourPoint;
cout << *myPoint;

// Use operator '->'
myPoint -> X(8. 6);
cout << *myPoint;

// Cannot assign scoped pointers, because operator '=' is private
boost::scoped_ptr <Point> myPoint2 (new Point(1.0, 23.3));
// THIS CODE DOES NOT COMPILE myPoint = myPoint2;

// Illegal, cannot convert
// boost::scoped_ptr <Point> illegalVar (new double);

}

return 0;
}
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Cuchulainn



Joined: 18 Dec 2006
Posts: 461
Location: Amsterdam, the Netherlands

PostPosted: Wed Jan 21, 2009 1:05 pm    Post subject: 8. Smart Pointers Reply with quote

In C++ we use raw pointers; boost has functionality for smart pointers.

Questions:

1. What are the 3 largest potential pitfalls with raw pointers?
2. How does boost resolve these problems?
3. What is the difference between scoped pointers and auto_ptr? Which one to use and when?
4. Which boost smart pointers implements the Gamma (GOF) Flyweight pattern?
5. How to avoid dangling pointers?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Datasim Financial Forums Forum Index -> C++ Certification and Examinations: Advanced Level All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group