| | |
C++ destructor problem
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 22
Reputation:
Solved Threads: 0
Hi, Im new to c++ and Im struggling with something.
I have a load of classes that all connect to each other. I globally overloaded the << operator for each class. So in my main I do the following:
The first cout works fine but the second ne gives me a segementation fault. Now I know a segmentation fault is a problem with memory and the cnstructors and destructors. I put a cout statement in my destructor and to my surprise I saw that directly after the first cout<<y; statement is executed the destructor is called.
Im completely lost as to why this is. Any suggestions?
I have a load of classes that all connect to each other. I globally overloaded the << operator for each class. So in my main I do the following:
C++ Syntax (Toggle Plain Text)
FixedSizeMatrix y(5,5); cout<<y; cout<<y;
The first cout works fine but the second ne gives me a segementation fault. Now I know a segmentation fault is a problem with memory and the cnstructors and destructors. I put a cout statement in my destructor and to my surprise I saw that directly after the first cout<<y; statement is executed the destructor is called.
Im completely lost as to why this is. Any suggestions?
Show us your code.
Method operator<< should be,
Method operator<< should be,
C++ Syntax (Toggle Plain Text)
friend ostream &operator<<(ostream &out,const FixedSizeMatrix &ref){ ..... return out; }
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Apr 2008
Posts: 22
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
inline ostream& perator<<(ostream& os, FixedSizeMatrix obj) { }
•
•
Join Date: Apr 2008
Posts: 22
Reputation:
Solved Threads: 0
Sorry bout that...
C++ Syntax (Toggle Plain Text)
inline ostream& operator << (ostream& os, FixedSizeMatrix obj) { obj.print(os); return os; }
Try this. And inline won't do anything helpful by the way.
C++ Syntax (Toggle Plain Text)
ostream& operator << (ostream& os, FixedSizeMatrix& obj) { obj.print(os); return os; }
1) What word becomes shorter if you add a letter to it? [ Solved by : niek_e, Paul Thompson] 2) What does this sequence equal to : (.5u - .5a)(.5u-.5b)(.5u-.5c) ... 3) What is the 123456789 prime numer? Ask4Answer
![]() |
Similar Threads
- simple linked list implementation problem (C++)
- Virtual destructor Problem (C++)
- Help with variable declared inside an if block (C++)
- Don't alter main (C++)
Other Threads in the C++ Forum
- Previous Thread: Creating BOTS
- Next Thread: may pay money for vectorized MD5
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






