Sponsored Content
Full Discussion: C++ program crashes
Top Forums Programming C++ program crashes Post 302608233 by Corona688 on Friday 16th of March 2012 02:00:04 PM
Old 03-16-2012
When you assign one class to the other, all you're copying is the pointer, not the memory itself. So they both end up holding pointers to the same memory.

When they go out of scope, they both try to free the same pointer. The first will succeed. The second to go out of scope will crash.

You should create a copy constructor for the class, which will be used whenever you assign another class to it with =.

Code:
class CString
{
...

CString(const CString& copy)
{
        m_data=new char[strlen(copy.m_data) + 1];
        strcpy(m_data, copy.m_data);
}

...

};

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. HP-UX

Program crashes with optimization level O2

I am experiencing a difficulty undersatnding why my program (C++, HP UNIX) crashes. It crashes only when I build it with -O (+O2) optimization switch (used in aCC compiler). It works ok with +O0 or +O1 optimization. Also, I see that local variables are shown incorrecly when program is built... (3 Replies)
Discussion started by: Yuriy07
3 Replies

2. Programming

AIX 5.3 64-bit program crashes with AIX 5.1

I have an AIX 64-bit program which uses following from AIX5.3 /usr/lib/libc.a(shr_64.o) /usr/lib/libpthread.a(shr_xpg5_64.o) /home/jeet_xp/export/power/usr/lib/libsarpc.a(shr.o) /unix /usr/lib/libcrypt.a(shr_64.o) /usr/lib/libc_r.a(shr_64.o) ... (3 Replies)
Discussion started by: jeet_xp
3 Replies

3. Linux

gethostnameby_r crashes

Hello all, I'm trying to use gethostbyname_r function with 6 arguments in one of my functions. But the call to this crashes the program. Kindly help me in resolving this... Compiler Info: Linux target: i686-hardhat-linux version: 3.3.1 The following is the piece of code I'm trying to... (1 Reply)
Discussion started by: rajans
1 Replies

4. Programming

C++ program crashes

Hi, Could anyone tell me the reason why the following program crashes? class A { int x; public: A() { cout << "from A()" << endl; } ~A() { cout << "from ~A()" << endl; } }; class B : public A { public: B() { cout << "from B()"... (2 Replies)
Discussion started by: royalibrahim
2 Replies

5. SuSE

Chromium flashes and crashes

I am running openSUSE 11.2 with KDE4.5 on my eMachines e525. I just did a "zypper up" on my system and it reported that Chromium was going to be updated. I agreed and the when the update was finished I shut down Chromium and started it again. It flickered on the screen for a moment and crashed.... (6 Replies)
Discussion started by: Druonysus
6 Replies

6. Solaris

Server crashes when not in use.

Production server crashes when there is no traffic on it. Can only recover by going to ALOM and reboot the server. This seems to happen about the same time every month. The only good thing is the server is not in production at the time of the crash. I have been unable to locate any information in... (5 Replies)
Discussion started by: Joeentech
5 Replies

7. Red Hat

7z crashes system

Can someone tell my why every time I try to use 7z it freezes my system? I can't move my mouse, I can't type, I can't kill my xsession. I then restart my system and everything returns to normal. When I try to use 7z my system again freezes. (11 Replies)
Discussion started by: cokedude
11 Replies

8. Programming

Program crashes on calling __libc_msgrcv()

Hi, I am a newbie to linux programming. I have implemented msgqueue in C. msgrcv() call at the client end is as below: msgrcv( msgqid, msgptr, msgsize, msgtype, 0 ); My program works fine when msgrcv () from /lib/libc.so.6 is called. However it crashes when __libc_msgrcv() is called. ... (3 Replies)
Discussion started by: praasanna
3 Replies

9. UNIX and Linux Applications

Apcupsd crashes

I am trying to run apcupsd, but it will not retain contact the UPS root@meow:/home/ethan/UPS/gapcmon-0.8.9# /etc/init.d/apcupsd start Starting UPS power management: A copy of the daemon is still running. If you just stopped it, please wait about 5 seconds for it to shut down.... (0 Replies)
Discussion started by: Meow613
0 Replies

10. Web Development

Apache2 Crashes

The Apache server suddenly stops. I am running Debian Jessie Here are some diagnostics: root@meow:/var/www# apachectl configtest AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress... (4 Replies)
Discussion started by: Meow613
4 Replies
FvwmScroll(1)						      General Commands Manual						     FvwmScroll(1)

NAME
FvwmScroll - the FVWM scroll-bar module SYNOPSIS
FvwmScroll is spawned by fvwm, so no command line invocation will work. DESCRIPTION
The FvwmScroll module prompts the user to select a target window, if the module was not launched from within a window context in Fvwm. After that, it adds scroll bars to the selected window, to reduce the total desktop space consumed by the window. FvwmScroll reads the same .fvwmrc file as fvwm reads when it starts up, and looks for lines similar to "*FvwmScrollFore green". FvwmScroll should not be used with windows which move or resize themselves, nor should it be used with windows which set the WM_COL- ORMAP_WINDOWS property. Operation is fine with windows that have a private colormap. COPYRIGHTS
The FvwmScroll program, and the concept for interfacing this module to the Window Manager, are all original work by Robert Nation. Copyright 1994, Robert Nation. No guarantees or warranties or anything are provided or implied in any way whatsoever. Use this program at your own risk. Permission to use this program for any purpose is given, as long as the copyright is kept intact. INITIALIZATION
During initialization, FvwmScroll will eventually search a configuration file which describes the colors to use. The configuration file is the same file that fvwm used during initialization. If the FvwmScroll executable is linked to another name, ie ln -s FvwmScroll MoreScroll, then another module called MoreScroll can be started, with a completely different configuration than FvwmScroll, simply by changing the keyword FvwmScroll to MoreScroll. INVOCATION
FvwmScroll can be invoked by binding the action 'Module FvwmScroll x y' to a menu or key-stroke in the .fvwmrc file. The parameter x and y are integers, which describe the horizontal and vertical window size reduction. Fvwm will search directory specified in the ModulePath configuration option to attempt to locate FvwmScroll. Although nothing keeps you from launching FvwmScroll at start-up time, you probably don't want to. CONFIGURATION OPTIONS
FvwmScroll reads the same .fvwmrc file as fvwm reads when it starts up, and looks for lines as listed below: *FvwmScrollFore color Tells the module to use color instead of grey for scroll bars themselves. *FvwmScrollBack color Tells the module to use color instead of black for the window background. BUGS
When the scroll bars are removed by clicking on the button in the lower right corner, the window does not restore its location correctly. AUTHOR
Robert Nation 3rd Berkeley Distribution April 14 1994 FvwmScroll(1)
All times are GMT -4. The time now is 11:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy