C/C++ Help
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Remember me

Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
Unread Dev Articles Community Forums Sponsor:
Old September 23rd, 2008, 05:20 PM
AuraofMana AuraofMana is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
Join Date: Sep 2008
Posts: 28 AuraofMana User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 11 sec
Reputation Power: 0
Hmm... I did this project on putty, with the g++ thing, which was what the school provided. I recently got my hands on Microsoft Visual Studio Professional Version, so I will be trying my hands on the IDE there. I've heard nothing but good things about it.
This is relevant because I didn't know how to test memory leaks and whatnot (or even use the debugger) on putty, but I am sure it'll be easier for me to learn it on the C++ IDE.
Again, thanks for your help Gotta go prepare for the C++ test tomorrow (After 2 semesters of college, this being the 3rd, I still don't get testing CS related things on paper, but whatever), I hope he doesn't provide some wacky questions about memory leaks.

Reply With Quote
Old September 24th, 2008, 04:56 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 15
Visual Studio is a very good product, even though it is from microsoft ;-)

If you have time, try to compile and run the following program:
cpp Code:
Original - cpp Code
  1. #include <iostream>
  3. using namespace std;
  5. struct A
  6. {
  7.    A() { cout << "constructor\n"; }
  9.    ~A() { cout << "destructor\n"; }
  11.    A( const A& a ) { cout << "copy constructor\n"; }
  13.    A& operator=( const A& a ) { cout << "assignment operator\n"; return *this; }
  15.    A& getA()
  16.    {
  17.       A* a = new A();
  18.       return *a;
  19.    }
  20. };
  22. int main()
  23. {
  24.    {
  25.       A a;
  26.       A b = a.getA();
  27.    }
  28. }
the struct A is what I call my 'tracer' class. (Classes and structs are the same, except that members/base in a class are by default private and in a struct they are public).
The A class prints exactly what happens to it, (copy) construction, destruction, and assignment.

The getA member function is like the subString() function in AltString, right? Run this code, count all the constructors, copy constructors and destructors. No memory leak roughly means that the sum of constructors + copy constructors should equal the number of destructors. You will see in this piece of code that that is not the case. It does not matter if you would change the line to
A& b = a.getA();
a = a.getA();
all of them have memory leaks.

I hope this thread has not turned you away from coding, once things start falling into place coding can be really fun and challenging.
There is no such thing as C/C++, you either program C or C++

Reply With Quote

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Weird Segmentation Fault

Developer Shed Advertisers and Affiliates

Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.

© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap