Click here to Skip to main content
15,921,371 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: oops Pin
toxcct18-May-05 3:08
toxcct18-May-05 3:08 
QuestionPointers to vectors? Pin
knapak29-Apr-05 9:25
knapak29-Apr-05 9:25 
AnswerRe: Pointers to vectors? Pin
Stuart Dootson29-Apr-05 9:52
professionalStuart Dootson29-Apr-05 9:52 
GeneralRe: Pointers to vectors? Pin
knapak29-Apr-05 10:04
knapak29-Apr-05 10:04 
GeneralRe: Pointers to vectors? Pin
markkuk29-Apr-05 10:46
markkuk29-Apr-05 10:46 
GeneralRe: Pointers to vectors? Pin
knapak29-Apr-05 10:54
knapak29-Apr-05 10:54 
GeneralRe: Pointers to vectors? Pin
knapak29-Apr-05 12:45
knapak29-Apr-05 12:45 
GeneralRe: Pointers to vectors? Pin
Stuart Dootson29-Apr-05 22:25
professionalStuart Dootson29-Apr-05 22:25 
As I said in my first reply, return the vector object - otherwise the storage associated with the vector is deallocated when the function exits.

If you did a similar thing with arrays, like below, you'd have the same problem.

double *CreateArray(double such)
{
   double pt_tovector[2];
   pt_tovector[0] = such;
   pt_tovector[1] = such;
   return pt_tovector;
}


Of course, if you allocated the array on the heap like the example below, you *CAN* return the array pointer. The thing is, the vector encapsulates and manages a pointer to heap storage - if you think of the vector as a pointer to an array in heap storage with other useful properties (like knowing how big the array is - a pointer won't tell you that), that may help.

double *CreateArray(double such)
{
   double* pt_tovector = new double[2];
   pt_tovector[0] = such;
   pt_tovector[1] = such;
   return pt_tovector;
}


BTW - iterators in VC7.1 are not pointers. They were in VC6, but there is no guarantee that iterators are pointers.

Stuart Dootson

'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
GeneralRe: Pointers to vectors? Pin
knapak2-May-05 9:55
knapak2-May-05 9:55 
GeneralRe: Pointers to vectors? Pin
markkuk30-Apr-05 11:56
markkuk30-Apr-05 11:56 
GeneralRe: Pointers to vectors? Pin
knapak2-May-05 9:57
knapak2-May-05 9:57 
QuestionHow do I save/load STL data (map & vector) Pin
Larry Mills Sr26-Apr-05 15:33
Larry Mills Sr26-Apr-05 15:33 
AnswerRe: How do I save/load STL data (map & vector) Pin
Alexandru Savescu28-Apr-05 1:27
Alexandru Savescu28-Apr-05 1:27 
AnswerRe: How do I save/load STL data (map & vector) Pin
CP Visitor2-May-05 23:00
CP Visitor2-May-05 23:00 
GeneralBHO: Getting the title of the page loaded Pin
alanwolfen25-Apr-05 22:41
alanwolfen25-Apr-05 22:41 
GeneralRe: BHO: Getting the title of the page loaded Pin
ThatsAlok25-Apr-05 23:28
ThatsAlok25-Apr-05 23:28 
GeneralRe: BHO: Getting the title of the page loaded Pin
alanwolfen26-Apr-05 14:13
alanwolfen26-Apr-05 14:13 
GeneralUse science for programs Pin
Member 191102425-Apr-05 9:45
Member 191102425-Apr-05 9:45 
GeneralRe: Use science for programs Pin
abecedarian25-Apr-05 10:35
abecedarian25-Apr-05 10:35 
GeneralRe: Use science for programs Pin
ThatsAlok28-Apr-05 2:37
ThatsAlok28-Apr-05 2:37 
GeneralRe: Use science for programs Pin
toxcct18-May-05 3:13
toxcct18-May-05 3:13 
GeneralRe: Use science for programs Pin
toxcct18-May-05 3:11
toxcct18-May-05 3:11 
GeneralTemplates with Variable argument List Pin
sijis22-Apr-05 20:09
sijis22-Apr-05 20:09 
GeneralRe: Templates with Variable argument List Pin
Joaquín M López Muñoz23-Apr-05 9:08
Joaquín M López Muñoz23-Apr-05 9:08 
GeneralRe: Templates with Variable argument List Pin
Nemanja Trifunovic23-Apr-05 16:03
Nemanja Trifunovic23-Apr-05 16:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.