| | |
destructor question
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2009
Posts: 14
Reputation:
Solved Threads: 0
c++ Syntax (Toggle Plain Text)
typedef vector<string> pipeline; typedef vector<pipeline> subPipelineStrings; subPipelineStrings* m_subPipelineStrings m_subPipelineStrings = new subPipelineStrings(3); string *s1 = new string("s1"); string *s2 = new string("s2"); string *s3 = new string("s3"); for (int i = 0; i < m_subPipelineStrings ->size();++i) { pipeline &p = m_subPipelineStrings->at(i); p.push_back(*s1) ; p.push_back(*s2) ; p.push_back(*s3) ; }
Thank you in advance!
Stay away from those pointers.
lines 8-10: delete those lines
lines 16-18:
With the above changes you don't have to worry about a destructor because the vector and string classes with destroy themselves.
lines 8-10: delete those lines
lines 16-18:
C++ Syntax (Toggle Plain Text)
p.push_back(string("s1")) ; p.push_back(string("s2")) ; p.push_back(string("s3")) ;
With the above changes you don't have to worry about a destructor because the vector and string classes with destroy themselves.
Last edited by Ancient Dragon; May 31st, 2009 at 2:34 pm.
The code you posted appears to contain a memory leak. You don't have to worry about destroying those vectors because the vector class will destroy itself when the class or program terminates.
If s1, s2 and s3 are being allocated somewhere else with new operator, then you need to delete them after push_back() is called (after line 19 of the code snippet you posted).
If s1, s2 and s3 are being allocated somewhere else with new operator, then you need to delete them after push_back() is called (after line 19 of the code snippet you posted).
Last edited by Ancient Dragon; May 31st, 2009 at 2:49 pm.
•
•
Join Date: May 2009
Posts: 14
Reputation:
Solved Threads: 0
•
•
•
•
The code you posted appears to contain a memory leak. You don't have to worry about destroying those vectors because the vector class will destroy itself when the class or program terminates.
If s1, s2 and s3 are being allocated somewhere else with new operator, then you need to delete them after push_back() is called (after line 19 of the code snippet you posted).
Last edited by yakovm; May 31st, 2009 at 2:58 pm.
![]() |
Similar Threads
- singleton pattern and its destructor... (C++)
- Linked List question (C++)
- General VB Question (VB.NET)
- Const Question - Why is this happening? (C++)
- Problem with destructor behavior (C++)
- Constructor overloading question (C++)
- class question (C++)
- use of destructor (C++)
- Initializing a member of a class with another const/destructor! (C++)
Other Threads in the C++ Forum
- Previous Thread: basis server creation fail using pipes ???
- Next Thread: sudoku c++ help :D
Views: 265 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






